home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / binutils.252 / gas / config / tc-hppa.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-20  |  154.3 KB  |  6,236 lines

  1. /* tc-hppa.c -- Assemble for the PA
  2.    Copyright (C) 1989 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GAS, the GNU Assembler.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 1, or (at your option)
  9.    any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GAS; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* HP PA-RISC support was contributed by the Center for Software Science
  22.    at the University of Utah.  */
  23.  
  24. #include <stdio.h>
  25. #include <ctype.h>
  26.  
  27. #include "as.h"
  28. #include "subsegs.h"
  29.  
  30. #include "../bfd/libhppa.h"
  31. #include "../bfd/libbfd.h"
  32.  
  33. /* Be careful, this file includes data *declarations*.  */
  34. #include "opcode/hppa.h"
  35.  
  36. /* A "convient" place to put object file dependencies which do
  37.    not need to be seen outside of tc-hppa.c.  */
  38. #ifdef OBJ_ELF
  39. /* Names of various debugging spaces/subspaces.  */
  40. #define GDB_DEBUG_SPACE_NAME ".stab"
  41. #define GDB_STRINGS_SUBSPACE_NAME ".stabstr"
  42. #define GDB_SYMBOLS_SUBSPACE_NAME ".stab"
  43. #define UNWIND_SECTION_NAME ".PARISC.unwind"
  44. /* Nonzero if CODE is a fixup code needing further processing.  */
  45.  
  46. /* Object file formats specify relocation types.  */
  47. typedef elf32_hppa_reloc_type reloc_type;
  48.  
  49. /* Object file formats specify BFD symbol types.  */
  50. typedef elf_symbol_type obj_symbol_type;
  51.  
  52. /* How to generate a relocation.  */
  53. #define hppa_gen_reloc_type hppa_elf_gen_reloc_type
  54.  
  55. /* ELF objects can have versions, but apparently do not have anywhere
  56.    to store a copyright string.  */
  57. #define obj_version obj_elf_version
  58. #define obj_copyright obj_elf_version
  59.  
  60. /* Use space aliases.  */
  61. #define USE_ALIASES 1
  62. #endif
  63.  
  64. #ifdef OBJ_SOM
  65. /* Names of various debugging spaces/subspaces.  */
  66. #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
  67. #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
  68. #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
  69. #define UNWIND_SECTION_NAME "$UNWIND$"
  70.  
  71. /* Object file formats specify relocation types.  */
  72. typedef int reloc_type;
  73.  
  74. /* SOM objects can have both a version string and a copyright string.  */
  75. #define obj_version obj_som_version
  76. #define obj_copyright obj_som_copyright
  77.  
  78. /* Do not use space aliases.  */
  79. #define USE_ALIASES 0
  80.  
  81. /* How to generate a relocation.  */
  82. #define hppa_gen_reloc_type hppa_som_gen_reloc_type
  83.  
  84. /* Object file formats specify BFD symbol types.  */
  85. typedef som_symbol_type obj_symbol_type;
  86.  
  87. /* This apparently isn't in older versions of hpux reloc.h.  */
  88. #ifndef R_DLT_REL
  89. #define R_DLT_REL 0x78
  90. #endif
  91. #endif
  92.  
  93. /* Various structures and types used internally in tc-hppa.c.  */
  94.  
  95. /* Unwind table and descriptor.  FIXME: Sync this with GDB version.  */
  96.  
  97. struct unwind_desc
  98.   {
  99.     unsigned int cannot_unwind:1;
  100.     unsigned int millicode:1;
  101.     unsigned int millicode_save_rest:1;
  102.     unsigned int region_desc:2;
  103.     unsigned int save_sr:2;
  104.     unsigned int entry_fr:4;
  105.     unsigned int entry_gr:5;
  106.     unsigned int args_stored:1;
  107.     unsigned int call_fr:5;
  108.     unsigned int call_gr:5;
  109.     unsigned int save_sp:1;
  110.     unsigned int save_rp:1;
  111.     unsigned int save_rp_in_frame:1;
  112.     unsigned int extn_ptr_defined:1;
  113.     unsigned int cleanup_defined:1;
  114.  
  115.     unsigned int hpe_interrupt_marker:1;
  116.     unsigned int hpux_interrupt_marker:1;
  117.     unsigned int reserved:3;
  118.     unsigned int frame_size:27;
  119.   };
  120.  
  121. struct unwind_table
  122.   {
  123.     /* Starting and ending offsets of the region described by
  124.        descriptor.  */
  125.     unsigned int start_offset;
  126.     unsigned int end_offset;
  127.     struct unwind_desc descriptor;
  128.   };
  129.  
  130. /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
  131.    control the entry and exit code they generate. It is also used in
  132.    creation of the correct stack unwind descriptors.
  133.  
  134.    NOTE:  GAS does not support .enter and .leave for the generation of
  135.    prologues and epilogues.  FIXME.
  136.  
  137.    The fields in structure roughly correspond to the arguments available on the
  138.    .callinfo pseudo-op.  */
  139.  
  140. struct call_info
  141.   {
  142.     /* The unwind descriptor being built.  */
  143.     struct unwind_table ci_unwind;
  144.  
  145.     /* Name of this function.  */
  146.     symbolS *start_symbol;
  147.  
  148.     /* (temporary) symbol used to mark the end of this function.  */
  149.     symbolS *end_symbol;
  150.  
  151.     /* Next entry in the chain.  */
  152.     struct call_info *ci_next;
  153.   };
  154.  
  155. /* Operand formats for FP instructions.   Note not all FP instructions
  156.    allow all four formats to be used (for example fmpysub only allows
  157.    SGL and DBL).  */
  158. typedef enum
  159.   {
  160.     SGL, DBL, ILLEGAL_FMT, QUAD
  161.   }
  162. fp_operand_format;
  163.  
  164. /* This fully describes the symbol types which may be attached to
  165.    an EXPORT or IMPORT directive.  Only SOM uses this formation
  166.    (ELF has no need for it).  */
  167. typedef enum
  168.   {
  169.     SYMBOL_TYPE_UNKNOWN,
  170.     SYMBOL_TYPE_ABSOLUTE,
  171.     SYMBOL_TYPE_CODE,
  172.     SYMBOL_TYPE_DATA,
  173.     SYMBOL_TYPE_ENTRY,
  174.     SYMBOL_TYPE_MILLICODE,
  175.     SYMBOL_TYPE_PLABEL,
  176.     SYMBOL_TYPE_PRI_PROG,
  177.     SYMBOL_TYPE_SEC_PROG,
  178.   }
  179. pa_symbol_type;
  180.  
  181. /* This structure contains information needed to assemble
  182.    individual instructions.  */
  183. struct pa_it
  184.   {
  185.     /* Holds the opcode after parsing by pa_ip.  */
  186.     unsigned long opcode;
  187.  
  188.     /* Holds an expression associated with the current instruction.  */
  189.     expressionS exp;
  190.  
  191.     /* Does this instruction use PC-relative addressing.  */
  192.     int pcrel;
  193.  
  194.     /* Floating point formats for operand1 and operand2.  */
  195.     fp_operand_format fpof1;
  196.     fp_operand_format fpof2;
  197.  
  198.     /* Holds the field selector for this instruction
  199.        (for example L%, LR%, etc).  */
  200.     long field_selector;
  201.  
  202.     /* Holds any argument relocation bits associated with this
  203.        instruction.  (instruction should be some sort of call).  */
  204.     long arg_reloc;
  205.  
  206.     /* The format specification for this instruction.  */
  207.     int format;
  208.  
  209.     /* The relocation (if any) associated with this instruction.  */
  210.     reloc_type reloc;
  211.   };
  212.  
  213. /* PA-89 floating point registers are arranged like this:
  214.  
  215.  
  216.    +--------------+--------------+
  217.    |   0 or 16L   |  16 or 16R   |
  218.    +--------------+--------------+
  219.    |   1 or 17L   |  17 or 17R   |
  220.    +--------------+--------------+
  221.    |              |              |
  222.  
  223.    .              .              .
  224.    .              .              .
  225.    .              .              .
  226.  
  227.    |              |              |
  228.    +--------------+--------------+
  229.    |  14 or 30L   |  30 or 30R   |
  230.    +--------------+--------------+
  231.    |  15 or 31L   |  31 or 31R   |
  232.    +--------------+--------------+
  233.  
  234.  
  235.    The following is a version of pa_parse_number that
  236.    handles the L/R notation and returns the correct
  237.    value to put into the instruction register field.
  238.    The correct value to put into the instruction is
  239.    encoded in the structure 'pa_89_fp_reg_struct'.  */
  240.  
  241. struct pa_89_fp_reg_struct
  242.   {
  243.     /* The register number.  */
  244.     char number_part;
  245.  
  246.     /* L/R selector.  */
  247.     char l_r_select;
  248.   };
  249.  
  250. /* Additional information needed to build argument relocation stubs.  */
  251. struct call_desc
  252.   {
  253.     /* The argument relocation specification.  */
  254.     unsigned int arg_reloc;
  255.  
  256.     /* Number of arguments.  */
  257.     unsigned int arg_count;
  258.   };
  259.  
  260. /* This structure defines an entry in the subspace dictionary
  261.    chain.  */
  262.  
  263. struct subspace_dictionary_chain
  264.   {
  265.     /* Nonzero if this space has been defined by the user code.  */
  266.     unsigned int ssd_defined;
  267.  
  268.     /* Name of this subspace.  */
  269.     char *ssd_name;
  270.  
  271.     /* GAS segment and subsegment associated with this subspace.  */
  272.     asection *ssd_seg;
  273.     int ssd_subseg;
  274.  
  275.     /* Next space in the subspace dictionary chain.  */
  276.     struct subspace_dictionary_chain *ssd_next;
  277.   };
  278.  
  279. typedef struct subspace_dictionary_chain ssd_chain_struct;
  280.  
  281. /* This structure defines an entry in the subspace dictionary
  282.    chain.  */
  283.  
  284. struct space_dictionary_chain
  285.   {
  286.     /* Nonzero if this space has been defined by the user code or
  287.        as a default space.  */
  288.     unsigned int sd_defined;
  289.  
  290.     /* Nonzero if this spaces has been defined by the user code.  */
  291.     unsigned int sd_user_defined;
  292.  
  293.     /* The space number (or index).  */
  294.     unsigned int sd_spnum;
  295.  
  296.     /* The name of this subspace.  */
  297.     char *sd_name;
  298.  
  299.     /* GAS segment to which this subspace corresponds.  */
  300.     asection *sd_seg;
  301.  
  302.     /* Current subsegment number being used.  */
  303.     int sd_last_subseg;
  304.  
  305.     /* The chain of subspaces contained within this space.  */
  306.     ssd_chain_struct *sd_subspaces;
  307.  
  308.     /* The next entry in the space dictionary chain.  */
  309.     struct space_dictionary_chain *sd_next;
  310.   };
  311.  
  312. typedef struct space_dictionary_chain sd_chain_struct;
  313.  
  314. /* Structure for previous label tracking.  Needed so that alignments,
  315.    callinfo declarations, etc can be easily attached to a particular
  316.    label.  */
  317. typedef struct label_symbol_struct
  318.   {
  319.     struct symbol *lss_label;
  320.     sd_chain_struct *lss_space;
  321.     struct label_symbol_struct *lss_next;
  322.   }
  323. label_symbol_struct;
  324.  
  325. /* This structure defines attributes of the default subspace
  326.    dictionary entries.  */
  327.  
  328. struct default_subspace_dict
  329.   {
  330.     /* Name of the subspace.  */
  331.     char *name;
  332.  
  333.     /* FIXME.  Is this still needed?  */
  334.     char defined;
  335.  
  336.     /* Nonzero if this subspace is loadable.  */
  337.     char loadable;
  338.  
  339.     /* Nonzero if this subspace contains only code.  */
  340.     char code_only;
  341.  
  342.     /* Nonzero if this is a common subspace.  */
  343.     char common;
  344.  
  345.     /* Nonzero if this is a common subspace which allows symbols
  346.        to be multiply defined.  */
  347.     char dup_common;
  348.  
  349.     /* Nonzero if this subspace should be zero filled.  */
  350.     char zero;
  351.  
  352.     /* Sort key for this subspace.  */
  353.     unsigned char sort;
  354.  
  355.     /* Access control bits for this subspace.  Can represent RWX access
  356.        as well as privilege level changes for gateways.  */
  357.     int access;
  358.  
  359.     /* Index of containing space.  */
  360.     int space_index;
  361.  
  362.     /* Alignment (in bytes) of this subspace.  */
  363.     int alignment;
  364.  
  365.     /* Quadrant within space where this subspace should be loaded.  */
  366.     int quadrant;
  367.  
  368.     /* An index into the default spaces array.  */
  369.     int def_space_index;
  370.  
  371.     /* An alias for this section (or NULL if no alias exists).  */
  372.     char *alias;
  373.  
  374.     /* Subsegment associated with this subspace.  */
  375.     subsegT subsegment;
  376.   };
  377.  
  378. /* This structure defines attributes of the default space
  379.    dictionary entries.  */
  380.  
  381. struct default_space_dict
  382.   {
  383.     /* Name of the space.  */
  384.     char *name;
  385.  
  386.     /* Space number.  It is possible to identify spaces within
  387.        assembly code numerically!  */
  388.     int spnum;
  389.  
  390.     /* Nonzero if this space is loadable.  */
  391.     char loadable;
  392.  
  393.     /* Nonzero if this space is "defined".  FIXME is still needed */
  394.     char defined;
  395.  
  396.     /* Nonzero if this space can not be shared.  */
  397.     char private;
  398.  
  399.     /* Sort key for this space.  */
  400.     unsigned char sort;
  401.  
  402.     /* Segment associated with this space.  */
  403.     asection *segment;
  404.  
  405.     /* An alias for this section (or NULL if no alias exists).  */
  406.     char *alias;
  407.   };
  408.  
  409. /* Extra information needed to perform fixups (relocations) on the PA.  */
  410. struct hppa_fix_struct
  411.   {
  412.     /* The field selector.  */
  413.     enum hppa_reloc_field_selector_type fx_r_field;
  414.  
  415.     /* Type of fixup.  */
  416.     int fx_r_type;
  417.  
  418.     /* Format of fixup.  */
  419.     int fx_r_format;
  420.  
  421.     /* Argument relocation bits.  */
  422.     long fx_arg_reloc;
  423.  
  424.     /* The segment this fixup appears in.  */
  425.     segT segment;
  426.   };
  427.  
  428. /* Structure to hold information about predefined registers.  */
  429.  
  430. struct pd_reg
  431.   {
  432.     char *name;
  433.     int value;
  434.   };
  435.  
  436. /* This structure defines the mapping from a FP condition string
  437.    to a condition number which can be recorded in an instruction.  */
  438. struct fp_cond_map
  439.   {
  440.     char *string;
  441.     int cond;
  442.   };
  443.  
  444. /* This structure defines a mapping from a field selector
  445.    string to a field selector type.  */
  446. struct selector_entry
  447.   {
  448.     char *prefix;
  449.     int field_selector;
  450.   };
  451.  
  452. /* Prototypes for functions local to tc-hppa.c.  */
  453.  
  454. static fp_operand_format pa_parse_fp_format PARAMS ((char **s));
  455. static void pa_cons PARAMS ((int));
  456. static void pa_data PARAMS ((int));
  457. static void pa_float_cons PARAMS ((int));
  458. static void pa_fill PARAMS ((int));
  459. static void pa_lcomm PARAMS ((int));
  460. static void pa_lsym PARAMS ((int));
  461. static void pa_stringer PARAMS ((int));
  462. static void pa_text PARAMS ((int));
  463. static void pa_version PARAMS ((int));
  464. static int pa_parse_fp_cmp_cond PARAMS ((char **));
  465. static int get_expression PARAMS ((char *));
  466. static int pa_get_absolute_expression PARAMS ((struct pa_it *, char **));
  467. static int evaluate_absolute PARAMS ((struct pa_it *));
  468. static unsigned int pa_build_arg_reloc PARAMS ((char *));
  469. static unsigned int pa_align_arg_reloc PARAMS ((unsigned int, unsigned int));
  470. static int pa_parse_nullif PARAMS ((char **));
  471. static int pa_parse_nonneg_cmpsub_cmpltr PARAMS ((char **, int));
  472. static int pa_parse_neg_cmpsub_cmpltr PARAMS ((char **, int));
  473. static int pa_parse_neg_add_cmpltr PARAMS ((char **, int));
  474. static int pa_parse_nonneg_add_cmpltr PARAMS ((char **, int));
  475. static void pa_block PARAMS ((int));
  476. static void pa_call PARAMS ((int));
  477. static void pa_call_args PARAMS ((struct call_desc *));
  478. static void pa_callinfo PARAMS ((int));
  479. static void pa_code PARAMS ((int));
  480. static void pa_comm PARAMS ((int));
  481. static void pa_copyright PARAMS ((int));
  482. static void pa_end PARAMS ((int));
  483. static void pa_enter PARAMS ((int));
  484. static void pa_entry PARAMS ((int));
  485. static void pa_equ PARAMS ((int));
  486. static void pa_exit PARAMS ((int));
  487. static void pa_export PARAMS ((int));
  488. static void pa_type_args PARAMS ((symbolS *, int));
  489. static void pa_import PARAMS ((int));
  490. static void pa_label PARAMS ((int));
  491. static void pa_leave PARAMS ((int));
  492. static void pa_origin PARAMS ((int));
  493. static void pa_proc PARAMS ((int));
  494. static void pa_procend PARAMS ((int));
  495. static void pa_space PARAMS ((int));
  496. static void pa_spnum PARAMS ((int));
  497. static void pa_subspace PARAMS ((int));
  498. static void pa_param PARAMS ((int));
  499. static void pa_undefine_label PARAMS ((void));
  500. static int need_89_opcode PARAMS ((struct pa_it *,
  501.                    struct pa_89_fp_reg_struct *));
  502. static int pa_parse_number PARAMS ((char **, struct pa_89_fp_reg_struct *));
  503. static label_symbol_struct *pa_get_label PARAMS ((void));
  504. static sd_chain_struct *create_new_space PARAMS ((char *, int, int,
  505.                           int, int, int,
  506.                           asection *, int));
  507. static ssd_chain_struct *create_new_subspace PARAMS ((sd_chain_struct *,
  508.                               char *, int, int,
  509.                               int, int, int,
  510.                               int, int, int, int,
  511.                               int, asection *));
  512. static ssd_chain_struct *update_subspace PARAMS ((sd_chain_struct *,
  513.                           char *, int, int, int,
  514.                           int, int, int, int,
  515.                           int, int, int,
  516.                           asection *));
  517. static sd_chain_struct *is_defined_space PARAMS ((char *));
  518. static ssd_chain_struct *is_defined_subspace PARAMS ((char *));
  519. static sd_chain_struct *pa_segment_to_space PARAMS ((asection *));
  520. static ssd_chain_struct *pa_subsegment_to_subspace PARAMS ((asection *,
  521.                                 subsegT));
  522. static sd_chain_struct *pa_find_space_by_number PARAMS ((int));
  523. static unsigned int pa_subspace_start PARAMS ((sd_chain_struct *, int));
  524. static void pa_ip PARAMS ((char *));
  525. static void fix_new_hppa PARAMS ((fragS *, int, int, symbolS *,
  526.                   long, expressionS *, int,
  527.                   bfd_reloc_code_real_type,
  528.                   enum hppa_reloc_field_selector_type,
  529.                   int, long, int *));
  530. static int is_end_of_statement PARAMS ((void));
  531. static int reg_name_search PARAMS ((char *));
  532. static int pa_chk_field_selector PARAMS ((char **));
  533. static int is_same_frag PARAMS ((fragS *, fragS *));
  534. static void pa_build_unwind_subspace PARAMS ((struct call_info *));
  535. static void process_exit PARAMS ((void));
  536. static sd_chain_struct *pa_parse_space_stmt PARAMS ((char *, int));
  537. static int log2 PARAMS ((int));
  538. static int pa_next_subseg PARAMS ((sd_chain_struct *));
  539. static unsigned int pa_stringer_aux PARAMS ((char *));
  540. static void pa_spaces_begin PARAMS ((void));
  541. static void hppa_elf_mark_end_of_function PARAMS ((void));
  542.  
  543. /* File and gloally scoped variable declarations.  */
  544.  
  545. /* Root and final entry in the space chain.  */
  546. static sd_chain_struct *space_dict_root;
  547. static sd_chain_struct *space_dict_last;
  548.  
  549. /* The current space and subspace.  */
  550. static sd_chain_struct *current_space;
  551. static ssd_chain_struct *current_subspace;
  552.  
  553. /* Root of the call_info chain.  */
  554. static struct call_info *call_info_root;
  555.  
  556. /* The last call_info (for functions) structure
  557.    seen so it can be associated with fixups and
  558.    function labels.  */
  559. static struct call_info *last_call_info;
  560.  
  561. /* The last call description (for actual calls).  */
  562. static struct call_desc last_call_desc;
  563.  
  564. /* Relaxation isn't supported for the PA yet.  */
  565. const relax_typeS md_relax_table[] =
  566. {0};
  567.  
  568. /* Jumps are always the same size -- one instruction.  */
  569. int md_short_jump_size = 4;
  570. int md_long_jump_size = 4;
  571.  
  572. /* handle of the OPCODE hash table */
  573. static struct hash_control *op_hash = NULL;
  574.  
  575. /* This array holds the chars that always start a comment.  If the
  576.    pre-processor is disabled, these aren't very useful.  */
  577. const char comment_chars[] = ";";
  578.  
  579. /* Table of pseudo ops for the PA.  FIXME -- how many of these
  580.    are now redundant with the overall GAS and the object file
  581.    dependent tables?  */
  582. const pseudo_typeS md_pseudo_table[] =
  583. {
  584.   /* align pseudo-ops on the PA specify the actual alignment requested,
  585.      not the log2 of the requested alignment.  */
  586.   {"align", s_align_bytes, 8},
  587.   {"block", pa_block, 1},
  588.   {"blockz", pa_block, 0},
  589.   {"byte", pa_cons, 1},
  590.   {"call", pa_call, 0},
  591.   {"callinfo", pa_callinfo, 0},
  592.   {"code", pa_code, 0},
  593.   {"comm", pa_comm, 0},
  594.   {"copyright", pa_copyright, 0},
  595.   {"data", pa_data, 0},
  596.   {"double", pa_float_cons, 'd'},
  597.   {"end", pa_end, 0},
  598.   {"enter", pa_enter, 0},
  599.   {"entry", pa_entry, 0},
  600.   {"equ", pa_equ, 0},
  601.   {"exit", pa_exit, 0},
  602.   {"export", pa_export, 0},
  603.   {"fill", pa_fill, 0},
  604.   {"float", pa_float_cons, 'f'},
  605.   {"half", pa_cons, 2},
  606.   {"import", pa_import, 0},
  607.   {"int", pa_cons, 4},
  608.   {"label", pa_label, 0},
  609.   {"lcomm", pa_lcomm, 0},
  610.   {"leave", pa_leave, 0},
  611.   {"long", pa_cons, 4},
  612.   {"lsym", pa_lsym, 0},
  613.   {"octa", pa_cons, 16},
  614.   {"org", pa_origin, 0},
  615.   {"origin", pa_origin, 0},
  616.   {"param", pa_param, 0},
  617.   {"proc", pa_proc, 0},
  618.   {"procend", pa_procend, 0},
  619.   {"quad", pa_cons, 8},
  620.   {"reg", pa_equ, 1},
  621.   {"short", pa_cons, 2},
  622.   {"single", pa_float_cons, 'f'},
  623.   {"space", pa_space, 0},
  624.   {"spnum", pa_spnum, 0},
  625.   {"string", pa_stringer, 0},
  626.   {"stringz", pa_stringer, 1},
  627.   {"subspa", pa_subspace, 0},
  628.   {"text", pa_text, 0},
  629.   {"version", pa_version, 0},
  630.   {"word", pa_cons, 4},
  631.   {NULL, 0, 0}
  632. };
  633.  
  634. /* This array holds the chars that only start a comment at the beginning of
  635.    a line.  If the line seems to have the form '# 123 filename'
  636.    .line and .file directives will appear in the pre-processed output.
  637.  
  638.    Note that input_file.c hand checks for '#' at the beginning of the
  639.    first line of the input file.  This is because the compiler outputs
  640.    #NO_APP at the beginning of its output.
  641.  
  642.    Also note that '/*' will always start a comment.  */
  643. const char line_comment_chars[] = "#";
  644.  
  645. /* This array holds the characters which act as line separators.  */
  646. const char line_separator_chars[] = "!";
  647.  
  648. /* Chars that can be used to separate mant from exp in floating point nums.  */
  649. const char EXP_CHARS[] = "eE";
  650.  
  651. /* Chars that mean this number is a floating point constant.
  652.    As in 0f12.456 or 0d1.2345e12.
  653.  
  654.    Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  655.    changed in read.c.  Ideally it shouldn't hae to know abou it at
  656.    all, but nothing is ideal around here.  */
  657. const char FLT_CHARS[] = "rRsSfFdDxXpP";
  658.  
  659. static struct pa_it the_insn;
  660.  
  661. /* Points to the end of an expression just parsed by get_expressoin
  662.    and friends.  FIXME.  This shouldn't be handled with a file-global
  663.    variable.  */
  664. static char *expr_end;
  665.  
  666. /* Nonzero if a .callinfo appeared within the current procedure.  */
  667. static int callinfo_found;
  668.  
  669. /* Nonzero if the assembler is currently within a .entry/.exit pair.  */
  670. static int within_entry_exit;
  671.  
  672. /* Nonzero if the assembler is currently within a procedure definition.  */
  673. static int within_procedure;
  674.  
  675. /* Handle on strucutre which keep track of the last symbol
  676.    seen in each subspace.  */
  677. static label_symbol_struct *label_symbols_rootp = NULL;
  678.  
  679. /* Holds the last field selector.  */
  680. static int hppa_field_selector;
  681.  
  682. /* A dummy bfd symbol so that all relocations have symbols of some kind.  */
  683. static symbolS *dummy_symbol;
  684.  
  685. /* Nonzero if errors are to be printed.  */
  686. static int print_errors = 1;
  687.  
  688. /* List of registers that are pre-defined:
  689.  
  690.    Each general register has one predefined name of the form
  691.    %r<REGNUM> which has the value <REGNUM>.
  692.  
  693.    Space and control registers are handled in a similar manner,
  694.    but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
  695.  
  696.    Likewise for the floating point registers, but of the form
  697.    %fr<REGNUM>.  Floating point registers have additional predefined
  698.    names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
  699.    again have the value <REGNUM>.
  700.  
  701.    Many registers also have synonyms:
  702.  
  703.    %r26 - %r23 have %arg0 - %arg3 as synonyms
  704.    %r28 - %r29 have %ret0 - %ret1 as synonyms
  705.    %r30 has %sp as a synonym
  706.    %r27 has %dp as a synonym
  707.    %r2  has %rp as a synonym
  708.  
  709.    Almost every control register has a synonym; they are not listed
  710.    here for brevity.
  711.  
  712.    The table is sorted. Suitable for searching by a binary search. */
  713.  
  714. static const struct pd_reg pre_defined_registers[] =
  715. {
  716.   {"%arg0", 26},
  717.   {"%arg1", 25},
  718.   {"%arg2", 24},
  719.   {"%arg3", 23},
  720.   {"%cr0", 0},
  721.   {"%cr10", 10},
  722.   {"%cr11", 11},
  723.   {"%cr12", 12},
  724.   {"%cr13", 13},
  725.   {"%cr14", 14},
  726.   {"%cr15", 15},
  727.   {"%cr16", 16},
  728.   {"%cr17", 17},
  729.   {"%cr18", 18},
  730.   {"%cr19", 19},
  731.   {"%cr20", 20},
  732.   {"%cr21", 21},
  733.   {"%cr22", 22},
  734.   {"%cr23", 23},
  735.   {"%cr24", 24},
  736.   {"%cr25", 25},
  737.   {"%cr26", 26},
  738.   {"%cr27", 27},
  739.   {"%cr28", 28},
  740.   {"%cr29", 29},
  741.   {"%cr30", 30},
  742.   {"%cr31", 31},
  743.   {"%cr8", 8},
  744.   {"%cr9", 9},
  745.   {"%dp", 27},
  746.   {"%eiem", 15},
  747.   {"%eirr", 23},
  748.   {"%fr0", 0},
  749.   {"%fr0l", 0},
  750.   {"%fr0r", 0},
  751.   {"%fr1", 1},
  752.   {"%fr10", 10},
  753.   {"%fr10l", 10},
  754.   {"%fr10r", 10},
  755.   {"%fr11", 11},
  756.   {"%fr11l", 11},
  757.   {"%fr11r", 11},
  758.   {"%fr12", 12},
  759.   {"%fr12l", 12},
  760.   {"%fr12r", 12},
  761.   {"%fr13", 13},
  762.   {"%fr13l", 13},
  763.   {"%fr13r", 13},
  764.   {"%fr14", 14},
  765.   {"%fr14l", 14},
  766.   {"%fr14r", 14},
  767.   {"%fr15", 15},
  768.   {"%fr15l", 15},
  769.   {"%fr15r", 15},
  770.   {"%fr16", 16},
  771.   {"%fr16l", 16},
  772.   {"%fr16r", 16},
  773.   {"%fr17", 17},
  774.   {"%fr17l", 17},
  775.   {"%fr17r", 17},
  776.   {"%fr18", 18},
  777.   {"%fr18l", 18},
  778.   {"%fr18r", 18},
  779.   {"%fr19", 19},
  780.   {"%fr19l", 19},
  781.   {"%fr19r", 19},
  782.   {"%fr1l", 1},
  783.   {"%fr1r", 1},
  784.   {"%fr2", 2},
  785.   {"%fr20", 20},
  786.   {"%fr20l", 20},
  787.   {"%fr20r", 20},
  788.   {"%fr21", 21},
  789.   {"%fr21l", 21},
  790.   {"%fr21r", 21},
  791.   {"%fr22", 22},
  792.   {"%fr22l", 22},
  793.   {"%fr22r", 22},
  794.   {"%fr23", 23},
  795.   {"%fr23l", 23},
  796.   {"%fr23r", 23},
  797.   {"%fr24", 24},
  798.   {"%fr24l", 24},
  799.   {"%fr24r", 24},
  800.   {"%fr25", 25},
  801.   {"%fr25l", 25},
  802.   {"%fr25r", 25},
  803.   {"%fr26", 26},
  804.   {"%fr26l", 26},
  805.   {"%fr26r", 26},
  806.   {"%fr27", 27},
  807.   {"%fr27l", 27},
  808.   {"%fr27r", 27},
  809.   {"%fr28", 28},
  810.   {"%fr28l", 28},
  811.   {"%fr28r", 28},
  812.   {"%fr29", 29},
  813.   {"%fr29l", 29},
  814.   {"%fr29r", 29},
  815.   {"%fr2l", 2},
  816.   {"%fr2r", 2},
  817.   {"%fr3", 3},
  818.   {"%fr30", 30},
  819.   {"%fr30l", 30},
  820.   {"%fr30r", 30},
  821.   {"%fr31", 31},
  822.   {"%fr31l", 31},
  823.   {"%fr31r", 31},
  824.   {"%fr3l", 3},
  825.   {"%fr3r", 3},
  826.   {"%fr4", 4},
  827.   {"%fr4l", 4},
  828.   {"%fr4r", 4},
  829.   {"%fr5", 5},
  830.   {"%fr5l", 5},
  831.   {"%fr5r", 5},
  832.   {"%fr6", 6},
  833.   {"%fr6l", 6},
  834.   {"%fr6r", 6},
  835.   {"%fr7", 7},
  836.   {"%fr7l", 7},
  837.   {"%fr7r", 7},
  838.   {"%fr8", 8},
  839.   {"%fr8l", 8},
  840.   {"%fr8r", 8},
  841.   {"%fr9", 9},
  842.   {"%fr9l", 9},
  843.   {"%fr9r", 9},
  844.   {"%hta", 25},
  845.   {"%iir", 19},
  846.   {"%ior", 21},
  847.   {"%ipsw", 22},
  848.   {"%isr", 20},
  849.   {"%itmr", 16},
  850.   {"%iva", 14},
  851.   {"%pcoq", 18},
  852.   {"%pcsq", 17},
  853.   {"%pidr1", 8},
  854.   {"%pidr2", 9},
  855.   {"%pidr3", 12},
  856.   {"%pidr4", 13},
  857.   {"%ppda", 24},
  858.   {"%r0", 0},
  859.   {"%r1", 1},
  860.   {"%r10", 10},
  861.   {"%r11", 11},
  862.   {"%r12", 12},
  863.   {"%r13", 13},
  864.   {"%r14", 14},
  865.   {"%r15", 15},
  866.   {"%r16", 16},
  867.   {"%r17", 17},
  868.   {"%r18", 18},
  869.   {"%r19", 19},
  870.   {"%r2", 2},
  871.   {"%r20", 20},
  872.   {"%r21", 21},
  873.   {"%r22", 22},
  874.   {"%r23", 23},
  875.   {"%r24", 24},
  876.   {"%r25", 25},
  877.   {"%r26", 26},
  878.   {"%r27", 27},
  879.   {"%r28", 28},
  880.   {"%r29", 29},
  881.   {"%r3", 3},
  882.   {"%r30", 30},
  883.   {"%r31", 31},
  884.   {"%r4", 4},
  885.   {"%r5", 5},
  886.   {"%r6", 6},
  887.   {"%r7", 7},
  888.   {"%r8", 8},
  889.   {"%r9", 9},
  890.   {"%rctr", 0},
  891.   {"%ret0", 28},
  892.   {"%ret1", 29},
  893.   {"%rp", 2},
  894.   {"%sar", 11},
  895.   {"%sp", 30},
  896.   {"%sr0", 0},
  897.   {"%sr1", 1},
  898.   {"%sr2", 2},
  899.   {"%sr3", 3},
  900.   {"%sr4", 4},
  901.   {"%sr5", 5},
  902.   {"%sr6", 6},
  903.   {"%sr7", 7},
  904.   {"%tr0", 24},
  905.   {"%tr1", 25},
  906.   {"%tr2", 26},
  907.   {"%tr3", 27},
  908.   {"%tr4", 28},
  909.   {"%tr5", 29},
  910.   {"%tr6", 30},
  911.   {"%tr7", 31}
  912. };
  913.  
  914. /* This table is sorted by order of the length of the string. This is
  915.    so we check for <> before we check for <. If we had a <> and checked
  916.    for < first, we would get a false match.  */
  917. static const struct fp_cond_map fp_cond_map[] =
  918. {
  919.   {"false?", 0},
  920.   {"false", 1},
  921.   {"true?", 30},
  922.   {"true", 31},
  923.   {"!<=>", 3},
  924.   {"!?>=", 8},
  925.   {"!?<=", 16},
  926.   {"!<>", 7},
  927.   {"!>=", 11},
  928.   {"!?>", 12},
  929.   {"?<=", 14},
  930.   {"!<=", 19},
  931.   {"!?<", 20},
  932.   {"?>=", 22},
  933.   {"!?=", 24},
  934.   {"!=t", 27},
  935.   {"<=>", 29},
  936.   {"=t", 5},
  937.   {"?=", 6},
  938.   {"?<", 10},
  939.   {"<=", 13},
  940.   {"!>", 15},
  941.   {"?>", 18},
  942.   {">=", 21},
  943.   {"!<", 23},
  944.   {"<>", 25},
  945.   {"!=", 26},
  946.   {"!?", 28},
  947.   {"?", 2},
  948.   {"=", 4},
  949.   {"<", 9},
  950.   {">", 17}
  951. };
  952.  
  953. static const struct selector_entry selector_table[] =
  954. {
  955.   {"f", e_fsel},
  956.   {"l", e_lsel},
  957.   {"ld", e_ldsel},
  958.   {"lp", e_lpsel},
  959.   {"lr", e_lrsel},
  960.   {"ls", e_lssel},
  961.   {"lt", e_ltsel},
  962.   {"p", e_psel},
  963.   {"r", e_rsel},
  964.   {"rd", e_rdsel},
  965.   {"rp", e_rpsel},
  966.   {"rr", e_rrsel},
  967.   {"rs", e_rssel},
  968.   {"rt", e_rtsel},
  969.   {"t", e_tsel},
  970. };
  971.  
  972. /* default space and subspace dictionaries */
  973.  
  974. #define GDB_SYMBOLS          GDB_SYMBOLS_SUBSPACE_NAME
  975. #define GDB_STRINGS          GDB_STRINGS_SUBSPACE_NAME
  976.  
  977. /* pre-defined subsegments (subspaces) for the HPPA.  */
  978. #define SUBSEG_CODE   0
  979. #define SUBSEG_DATA   0
  980. #define SUBSEG_LIT    1
  981. #define SUBSEG_BSS    2
  982. #define SUBSEG_UNWIND 3
  983. #define SUBSEG_GDB_STRINGS 0
  984. #define SUBSEG_GDB_SYMBOLS 1
  985.  
  986. static struct default_subspace_dict pa_def_subspaces[] =
  987. {
  988.   {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE},
  989.   {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA},
  990.   {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT},
  991.   {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS},
  992. #ifdef OBJ_ELF
  993.   {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND},
  994. #endif
  995.   {NULL, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
  996. };
  997.  
  998. static struct default_space_dict pa_def_spaces[] =
  999. {
  1000.   {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL, ".text"},
  1001.   {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL, ".data"},
  1002.   {NULL, 0, 0, 0, 0, 0, ASEC_NULL, NULL}
  1003. };
  1004.  
  1005. /* Misc local definitions used by the assembler.  */
  1006.  
  1007. /* Return nonzero if the string pointed to by S potentially represents
  1008.    a right or left half of a FP register  */
  1009. #define IS_R_SELECT(S)   (*(S) == 'R' || *(S) == 'r')
  1010. #define IS_L_SELECT(S)   (*(S) == 'L' || *(S) == 'l')
  1011.  
  1012. /* These macros are used to maintain spaces/subspaces.  */
  1013. #define SPACE_DEFINED(space_chain)    (space_chain)->sd_defined
  1014. #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
  1015. #define SPACE_SPNUM(space_chain)    (space_chain)->sd_spnum
  1016. #define SPACE_NAME(space_chain)        (space_chain)->sd_name
  1017.  
  1018. #define SUBSPACE_DEFINED(ss_chain)    (ss_chain)->ssd_defined
  1019. #define SUBSPACE_NAME(ss_chain)        (ss_chain)->ssd_name
  1020.  
  1021. /* Insert FIELD into OPCODE starting at bit START.  Continue pa_ip
  1022.    main loop after insertion.  */
  1023.  
  1024. #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
  1025.   { \
  1026.     ((OPCODE) |= (FIELD) << (START)); \
  1027.     continue; \
  1028.   }
  1029.  
  1030. /* Simple range checking for FIELD againt HIGH and LOW bounds.
  1031.    IGNORE is used to suppress the error message.  */
  1032.  
  1033. #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
  1034.   { \
  1035.     if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
  1036.       { \
  1037.     if (! IGNORE) \
  1038.           as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
  1039.           (int) (FIELD));\
  1040.         break; \
  1041.       } \
  1042.   }
  1043.  
  1044. #define is_DP_relative(exp)            \
  1045.   ((exp).X_op == O_subtract            \
  1046.    && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
  1047.  
  1048. #define is_PC_relative(exp)            \
  1049.   ((exp).X_op == O_subtract            \
  1050.    && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
  1051.  
  1052. /* We need some complex handling for stabs (sym1 - sym2).  Luckily, we'll
  1053.    always be able to reduce the expression to a constant, so we don't
  1054.    need real complex handling yet.  */
  1055. #define is_complex(exp)                \
  1056.   ((exp).X_op != O_constant && (exp).X_op != O_symbol)
  1057.  
  1058. /* Actual functions to implement the PA specific code for the assembler.  */
  1059.  
  1060. /* Returns a pointer to the label_symbol_struct for the current space.
  1061.    or NULL if no label_symbol_struct exists for the current space.  */
  1062.  
  1063. static label_symbol_struct *
  1064. pa_get_label ()
  1065. {
  1066.   label_symbol_struct *label_chain;
  1067.   sd_chain_struct *space_chain = current_space;
  1068.  
  1069.   for (label_chain = label_symbols_rootp;
  1070.        label_chain;
  1071.        label_chain = label_chain->lss_next)
  1072.     if (space_chain == label_chain->lss_space && label_chain->lss_label)
  1073.       return label_chain;
  1074.  
  1075.   return NULL;
  1076. }
  1077.  
  1078. /* Defines a label for the current space.  If one is already defined,
  1079.    this function will replace it with the new label.  */
  1080.  
  1081. void
  1082. pa_define_label (symbol)
  1083.      symbolS *symbol;
  1084. {
  1085.   label_symbol_struct *label_chain = pa_get_label ();
  1086.   sd_chain_struct *space_chain = current_space;
  1087.  
  1088.   if (label_chain)
  1089.     label_chain->lss_label = symbol;
  1090.   else
  1091.     {
  1092.       /* Create a new label entry and add it to the head of the chain.  */
  1093.       label_chain
  1094.     = (label_symbol_struct *) xmalloc (sizeof (label_symbol_struct));
  1095.       label_chain->lss_label = symbol;
  1096.       label_chain->lss_space = space_chain;
  1097.       label_chain->lss_next = NULL;
  1098.  
  1099.       if (label_symbols_rootp)
  1100.     label_chain->lss_next = label_symbols_rootp;
  1101.  
  1102.       label_symbols_rootp = label_chain;
  1103.     }
  1104. }
  1105.  
  1106. /* Removes a label definition for the current space.
  1107.    If there is no label_symbol_struct entry, then no action is taken.  */
  1108.  
  1109. static void
  1110. pa_undefine_label ()
  1111. {
  1112.   label_symbol_struct *label_chain;
  1113.   label_symbol_struct *prev_label_chain = NULL;
  1114.   sd_chain_struct *space_chain = current_space;
  1115.  
  1116.   for (label_chain = label_symbols_rootp;
  1117.        label_chain;
  1118.        label_chain = label_chain->lss_next)
  1119.     {
  1120.       if (space_chain == label_chain->lss_space && label_chain->lss_label)
  1121.     {
  1122.       /* Remove the label from the chain and free its memory.  */
  1123.       if (prev_label_chain)
  1124.         prev_label_chain->lss_next = label_chain->lss_next;
  1125.       else
  1126.         label_symbols_rootp = label_chain->lss_next;
  1127.  
  1128.       free (label_chain);
  1129.       break;
  1130.     }
  1131.       prev_label_chain = label_chain;
  1132.     }
  1133. }
  1134.  
  1135.  
  1136. /* An HPPA-specific version of fix_new.  This is required because the HPPA
  1137.    code needs to keep track of some extra stuff.  Each call to fix_new_hppa
  1138.    results in the creation of an instance of an hppa_fix_struct.  An
  1139.    hppa_fix_struct stores the extra information along with a pointer to the
  1140.    original fixS.  This is attached to the original fixup via the
  1141.    tc_fix_data field.  */
  1142.  
  1143. static void
  1144. fix_new_hppa (frag, where, size, add_symbol, offset, exp, pcrel,
  1145.           r_type, r_field, r_format, arg_reloc, unwind_bits)
  1146.      fragS *frag;
  1147.      int where;
  1148.      int size;
  1149.      symbolS *add_symbol;
  1150.      long offset;
  1151.      expressionS *exp;
  1152.      int pcrel;
  1153.      bfd_reloc_code_real_type r_type;
  1154.      enum hppa_reloc_field_selector_type r_field;
  1155.      int r_format;
  1156.      long arg_reloc;
  1157.      int* unwind_bits;
  1158. {
  1159.   fixS *new_fix;
  1160.  
  1161.   struct hppa_fix_struct *hppa_fix = (struct hppa_fix_struct *)
  1162.   obstack_alloc (¬es, sizeof (struct hppa_fix_struct));
  1163.  
  1164.   if (exp != NULL)
  1165.     new_fix = fix_new_exp (frag, where, size, exp, pcrel, r_type);
  1166.   else
  1167.     new_fix = fix_new (frag, where, size, add_symbol, offset, pcrel, r_type);
  1168.   new_fix->tc_fix_data = (void *) hppa_fix;
  1169.   hppa_fix->fx_r_type = r_type;
  1170.   hppa_fix->fx_r_field = r_field;
  1171.   hppa_fix->fx_r_format = r_format;
  1172.   hppa_fix->fx_arg_reloc = arg_reloc;
  1173.   hppa_fix->segment = now_seg;
  1174. #ifdef OBJ_SOM
  1175.   if (r_type == R_ENTRY || r_type == R_EXIT)
  1176.     new_fix->fx_offset = *unwind_bits;
  1177. #endif
  1178.  
  1179.   /* foo-$global$ is used to access non-automatic storage.  $global$
  1180.      is really just a marker and has served its purpose, so eliminate
  1181.      it now so as not to confuse write.c.  */
  1182.   if (new_fix->fx_subsy
  1183.       && !strcmp (S_GET_NAME (new_fix->fx_subsy), "$global$"))
  1184.     new_fix->fx_subsy = NULL;
  1185. }
  1186.  
  1187. /* Parse a .byte, .word, .long expression for the HPPA.  Called by
  1188.    cons via the TC_PARSE_CONS_EXPRESSION macro.  */
  1189.  
  1190. void
  1191. parse_cons_expression_hppa (exp)
  1192.      expressionS *exp;
  1193. {
  1194.   hppa_field_selector = pa_chk_field_selector (&input_line_pointer);
  1195.   expression (exp);
  1196. }
  1197.  
  1198. /* This fix_new is called by cons via TC_CONS_FIX_NEW.
  1199.    hppa_field_selector is set by the parse_cons_expression_hppa.  */
  1200.  
  1201. void
  1202. cons_fix_new_hppa (frag, where, size, exp)
  1203.      fragS *frag;
  1204.      int where;
  1205.      int size;
  1206.      expressionS *exp;
  1207. {
  1208.   unsigned int rel_type;
  1209.  
  1210.   /* Get a base relocation type.  */
  1211.   if (is_DP_relative (*exp))
  1212.     rel_type = R_HPPA_GOTOFF;
  1213.   else if (is_complex (*exp))
  1214.     rel_type = R_HPPA_COMPLEX;
  1215.   else
  1216.     rel_type = R_HPPA;
  1217.  
  1218.   if (hppa_field_selector != e_psel && hppa_field_selector != e_fsel)
  1219.     as_warn ("Invalid field selector.  Assuming F%%.");
  1220.  
  1221.   fix_new_hppa (frag, where, size,
  1222.         (symbolS *) NULL, (offsetT) 0, exp, 0, rel_type,
  1223.         hppa_field_selector, 32, 0, NULL);
  1224.  
  1225.   /* Reset field selector to its default state.  */
  1226.   hppa_field_selector = 0;
  1227. }
  1228.  
  1229. /* This function is called once, at assembler startup time.  It should
  1230.    set up all the tables, etc. that the MD part of the assembler will need.  */
  1231.  
  1232. void
  1233. md_begin ()
  1234. {
  1235.   const char *retval = NULL;
  1236.   int lose = 0;
  1237.   unsigned int i = 0;
  1238.  
  1239.   last_call_info = NULL;
  1240.   call_info_root = NULL;
  1241.  
  1242.   /* Folding of text and data segments fails miserably on the PA.
  1243.      Warn user and disable "-R" option.  */
  1244.   if (flag_readonly_data_in_text)
  1245.     {
  1246.       as_warn ("-R option not supported on this target.");
  1247.       flag_readonly_data_in_text = 0;
  1248.     }
  1249.  
  1250.   pa_spaces_begin ();
  1251.  
  1252.   op_hash = hash_new ();
  1253.  
  1254.   while (i < NUMOPCODES)
  1255.     {
  1256.       const char *name = pa_opcodes[i].name;
  1257.       retval = hash_insert (op_hash, name, (struct pa_opcode *) &pa_opcodes[i]);
  1258.       if (retval != NULL && *retval != '\0')
  1259.     {
  1260.       as_fatal ("Internal error: can't hash `%s': %s\n", name, retval);
  1261.       lose = 1;
  1262.     }
  1263.       do
  1264.     {
  1265.       if ((pa_opcodes[i].match & pa_opcodes[i].mask)
  1266.           != pa_opcodes[i].match)
  1267.         {
  1268.           fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
  1269.                pa_opcodes[i].name, pa_opcodes[i].args);
  1270.           lose = 1;
  1271.         }
  1272.       ++i;
  1273.     }
  1274.       while (i < NUMOPCODES && !strcmp (pa_opcodes[i].name, name));
  1275.     }
  1276.  
  1277.   if (lose)
  1278.     as_fatal ("Broken assembler.  No assembly attempted.");
  1279.  
  1280.   /* SOM will change text_section.  To make sure we never put
  1281.      anything into the old one switch to the new one now.  */
  1282.   subseg_set (text_section, 0);
  1283.  
  1284.   dummy_symbol = symbol_find_or_make ("L$dummy");
  1285.   S_SET_SEGMENT (dummy_symbol, text_section);
  1286. }
  1287.  
  1288. /* Assemble a single instruction storing it into a frag.  */
  1289. void
  1290. md_assemble (str)
  1291.      char *str;
  1292. {
  1293.   char *to;
  1294.  
  1295.   /* The had better be something to assemble.  */
  1296.   assert (str);
  1297.  
  1298.   /* If we are within a procedure definition, make sure we've
  1299.      defined a label for the procedure; handle case where the
  1300.      label was defined after the .PROC directive.
  1301.  
  1302.      Note there's not need to diddle with the segment or fragment
  1303.      for the label symbol in this case.  We have already switched
  1304.      into the new $CODE$ subspace at this point.  */
  1305.   if (within_procedure && last_call_info->start_symbol == NULL)
  1306.     {
  1307.       label_symbol_struct *label_symbol = pa_get_label ();
  1308.  
  1309.       if (label_symbol)
  1310.     {
  1311.       if (label_symbol->lss_label)
  1312.         {
  1313.           last_call_info->start_symbol = label_symbol->lss_label;
  1314.           label_symbol->lss_label->bsym->flags |= BSF_FUNCTION;
  1315. #ifdef OBJ_SOM
  1316.           /* Also handle allocation of a fixup to hold the unwind
  1317.          information when the label appears after the proc/procend.  */
  1318.           if (within_entry_exit)
  1319.         {
  1320.           char *where = frag_more (0);
  1321.  
  1322.           fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  1323.                 NULL, (offsetT) 0, NULL,
  1324.                 0, R_HPPA_ENTRY, e_fsel, 0, 0,
  1325.                 (int *)&last_call_info->ci_unwind.descriptor);
  1326.         }
  1327. #endif
  1328.         }
  1329.       else
  1330.         as_bad ("Missing function name for .PROC (corrupted label chain)");
  1331.     }
  1332.       else
  1333.     as_bad ("Missing function name for .PROC");
  1334.     }
  1335.  
  1336.   /* Assemble the instruction.  Results are saved into "the_insn".  */
  1337.   pa_ip (str);
  1338.  
  1339.   /* Get somewhere to put the assembled instrution.  */
  1340.   to = frag_more (4);
  1341.  
  1342.   /* Output the opcode. */
  1343.   md_number_to_chars (to, the_insn.opcode, 4);
  1344.  
  1345.   /* If necessary output more stuff.  */
  1346.   if (the_insn.reloc != R_HPPA_NONE)
  1347.     fix_new_hppa (frag_now, (to - frag_now->fr_literal), 4, NULL,
  1348.           (offsetT) 0, &the_insn.exp, the_insn.pcrel,
  1349.           the_insn.reloc, the_insn.field_selector,
  1350.           the_insn.format, the_insn.arg_reloc, NULL);
  1351. }
  1352.  
  1353. /* Do the real work for assembling a single instruction.  Store results
  1354.    into the global "the_insn" variable.  */
  1355.  
  1356. static void
  1357. pa_ip (str)
  1358.      char *str;
  1359. {
  1360.   char *error_message = "";
  1361.   char *s, c, *argstart, *name, *save_s;
  1362.   const char *args;
  1363.   int match = FALSE;
  1364.   int comma = 0;
  1365.   int cmpltr, nullif, flag, cond, num;
  1366.   unsigned long opcode;
  1367.   struct pa_opcode *insn;
  1368.  
  1369.   /* Skip to something interesting.  */
  1370.   for (s = str; isupper (*s) || islower (*s) || (*s >= '0' && *s <= '3'); ++s)
  1371.     ;
  1372.  
  1373.   switch (*s)
  1374.     {
  1375.  
  1376.     case '\0':
  1377.       break;
  1378.  
  1379.     case ',':
  1380.       comma = 1;
  1381.  
  1382.       /*FALLTHROUGH */
  1383.  
  1384.     case ' ':
  1385.       *s++ = '\0';
  1386.       break;
  1387.  
  1388.     default:
  1389.       as_fatal ("Unknown opcode: `%s'", str);
  1390.     }
  1391.  
  1392.   save_s = str;
  1393.  
  1394.   /* Convert everything into lower case.  */
  1395.   while (*save_s)
  1396.     {
  1397.       if (isupper (*save_s))
  1398.     *save_s = tolower (*save_s);
  1399.       save_s++;
  1400.     }
  1401.  
  1402.   /* Look up the opcode in the has table.  */
  1403.   if ((insn = (struct pa_opcode *) hash_find (op_hash, str)) == NULL)
  1404.     {
  1405.       as_bad ("Unknown opcode: `%s'", str);
  1406.       return;
  1407.     }
  1408.  
  1409.   if (comma)
  1410.     {
  1411.       *--s = ',';
  1412.     }
  1413.  
  1414.   /* Mark the location where arguments for the instruction start, then
  1415.      start processing them.  */
  1416.   argstart = s;
  1417.   for (;;)
  1418.     {
  1419.       /* Do some initialization.  */
  1420.       opcode = insn->match;
  1421.       bzero (&the_insn, sizeof (the_insn));
  1422.  
  1423.       the_insn.reloc = R_HPPA_NONE;
  1424.  
  1425.       /* Build the opcode, checking as we go to make
  1426.          sure that the operands match.  */
  1427.       for (args = insn->args;; ++args)
  1428.     {
  1429.       switch (*args)
  1430.         {
  1431.  
  1432.         /* End of arguments.  */
  1433.         case '\0':
  1434.           if (*s == '\0')
  1435.         match = TRUE;
  1436.           break;
  1437.  
  1438.         case '+':
  1439.           if (*s == '+')
  1440.         {
  1441.           ++s;
  1442.           continue;
  1443.         }
  1444.           if (*s == '-')
  1445.         continue;
  1446.           break;
  1447.  
  1448.         /* These must match exactly.  */
  1449.         case '(':
  1450.         case ')':
  1451.         case ',':
  1452.         case ' ':
  1453.           if (*s++ == *args)
  1454.         continue;
  1455.           break;
  1456.  
  1457.         /* Handle a 5 bit register or control register field at 10.  */
  1458.         case 'b':
  1459.         case '^':
  1460.           num = pa_parse_number (&s, 0);
  1461.           CHECK_FIELD (num, 31, 0, 0);
  1462.           INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
  1463.  
  1464.         /* Handle a 5 bit register field at 15.  */
  1465.         case 'x':
  1466.           num = pa_parse_number (&s, 0);
  1467.           CHECK_FIELD (num, 31, 0, 0);
  1468.           INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
  1469.  
  1470.         /* Handle a 5 bit register field at 31.  */
  1471.         case 'y':
  1472.         case 't':
  1473.           num = pa_parse_number (&s, 0);
  1474.           CHECK_FIELD (num, 31, 0, 0);
  1475.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  1476.  
  1477.         /* Handle a 5 bit field length at 31.  */
  1478.         case 'T':
  1479.           num = pa_get_absolute_expression (&the_insn, &s);
  1480.           s = expr_end;
  1481.           CHECK_FIELD (num, 32, 1, 0);
  1482.           INSERT_FIELD_AND_CONTINUE (opcode, 32 - num, 0);
  1483.  
  1484.         /* Handle a 5 bit immediate at 15.  */
  1485.         case '5':
  1486.           num = pa_get_absolute_expression (&the_insn, &s);
  1487.           s = expr_end;
  1488.           CHECK_FIELD (num, 15, -16, 0);
  1489.           low_sign_unext (num, 5, &num);
  1490.           INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
  1491.  
  1492.         /* Handle a 5 bit immediate at 31.  */
  1493.         case 'V':
  1494.           num = pa_get_absolute_expression (&the_insn, &s);
  1495.           s = expr_end;
  1496.           CHECK_FIELD (num, 15, -16, 0)
  1497.         low_sign_unext (num, 5, &num);
  1498.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  1499.  
  1500.         /* Handle an unsigned 5 bit immediate at 31.  */
  1501.         case 'r':
  1502.           num = pa_get_absolute_expression (&the_insn, &s);
  1503.           s = expr_end;
  1504.           CHECK_FIELD (num, 31, 0, 0);
  1505.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  1506.  
  1507.         /* Handle an unsigned 5 bit immediate at 15.  */
  1508.         case 'R':
  1509.           num = pa_get_absolute_expression (&the_insn, &s);
  1510.           s = expr_end;
  1511.           CHECK_FIELD (num, 31, 0, 0);
  1512.           INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
  1513.  
  1514.         /* Handle a 2 bit space identifier at 17.  */
  1515.         case 's':
  1516.           num = pa_parse_number (&s, 0);
  1517.           CHECK_FIELD (num, 3, 0, 1);
  1518.           INSERT_FIELD_AND_CONTINUE (opcode, num, 14);
  1519.  
  1520.         /* Handle a 3 bit space identifier at 18.  */
  1521.         case 'S':
  1522.           num = pa_parse_number (&s, 0);
  1523.           CHECK_FIELD (num, 7, 0, 1);
  1524.           dis_assemble_3 (num, &num);
  1525.           INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
  1526.  
  1527.         /* Handle a completer for an indexing load or store.  */
  1528.         case 'c':
  1529.           {
  1530.         int uu = 0;
  1531.         int m = 0;
  1532.         int i = 0;
  1533.         while (*s == ',' && i < 2)
  1534.           {
  1535.             s++;
  1536.             if (strncasecmp (s, "sm", 2) == 0)
  1537.               {
  1538.             uu = 1;
  1539.             m = 1;
  1540.             s++;
  1541.             i++;
  1542.               }
  1543.             else if (strncasecmp (s, "m", 1) == 0)
  1544.               m = 1;
  1545.             else if (strncasecmp (s, "s", 1) == 0)
  1546.               uu = 1;
  1547.             else
  1548.               as_bad ("Invalid Indexed Load Completer.");
  1549.             s++;
  1550.             i++;
  1551.           }
  1552.         if (i > 2)
  1553.           as_bad ("Invalid Indexed Load Completer Syntax.");
  1554.         opcode |= m << 5;
  1555.         INSERT_FIELD_AND_CONTINUE (opcode, uu, 13);
  1556.           }
  1557.  
  1558.         /* Handle a short load/store completer.  */
  1559.         case 'C':
  1560.           {
  1561.         int a = 0;
  1562.         int m = 0;
  1563.         if (*s == ',')
  1564.           {
  1565.             s++;
  1566.             if (strncasecmp (s, "ma", 2) == 0)
  1567.               {
  1568.             a = 0;
  1569.             m = 1;
  1570.               }
  1571.             else if (strncasecmp (s, "mb", 2) == 0)
  1572.               {
  1573.             a = 1;
  1574.             m = 1;
  1575.               }
  1576.             else
  1577.               as_bad ("Invalid Short Load/Store Completer.");
  1578.             s += 2;
  1579.           }
  1580.         opcode |= m << 5;
  1581.         INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
  1582.           }
  1583.  
  1584.         /* Handle a stbys completer.  */
  1585.         case 'Y':
  1586.           {
  1587.         int a = 0;
  1588.         int m = 0;
  1589.         int i = 0;
  1590.         while (*s == ',' && i < 2)
  1591.           {
  1592.             s++;
  1593.             if (strncasecmp (s, "m", 1) == 0)
  1594.               m = 1;
  1595.             else if (strncasecmp (s, "b", 1) == 0)
  1596.               a = 0;
  1597.             else if (strncasecmp (s, "e", 1) == 0)
  1598.               a = 1;
  1599.             else
  1600.               as_bad ("Invalid Store Bytes Short Completer");
  1601.             s++;
  1602.             i++;
  1603.           }
  1604.         if (i > 2)
  1605.           as_bad ("Invalid Store Bytes Short Completer");
  1606.         opcode |= m << 5;
  1607.         INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
  1608.           }
  1609.  
  1610.         /* Handle a non-negated compare/stubtract condition.  */
  1611.         case '<':
  1612.           cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1);
  1613.           if (cmpltr < 0)
  1614.         {
  1615.           as_bad ("Invalid Compare/Subtract Condition: %c", *s);
  1616.           cmpltr = 0;
  1617.         }
  1618.           INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  1619.  
  1620.         /* Handle a negated or non-negated compare/subtract condition.  */
  1621.         case '?':
  1622.           save_s = s;
  1623.           cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1);
  1624.           if (cmpltr < 0)
  1625.         {
  1626.           s = save_s;
  1627.           cmpltr = pa_parse_neg_cmpsub_cmpltr (&s, 1);
  1628.           if (cmpltr < 0)
  1629.             {
  1630.               as_bad ("Invalid Compare/Subtract Condition.");
  1631.               cmpltr = 0;
  1632.             }
  1633.           else
  1634.             {
  1635.               /* Negated condition requires an opcode change.  */
  1636.               opcode |= 1 << 27;
  1637.             }
  1638.         }
  1639.           INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  1640.  
  1641.         /* Handle non-negated add condition.  */
  1642.         case '!':
  1643.           cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1);
  1644.           if (cmpltr < 0)
  1645.         {
  1646.           as_bad ("Invalid Compare/Subtract Condition: %c", *s);
  1647.           cmpltr = 0;
  1648.         }
  1649.           INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  1650.  
  1651.         /* Handle a negated or non-negated add condition.  */
  1652.         case '@':
  1653.           save_s = s;
  1654.           cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1);
  1655.           if (cmpltr < 0)
  1656.         {
  1657.           s = save_s;
  1658.           cmpltr = pa_parse_neg_add_cmpltr (&s, 1);
  1659.           if (cmpltr < 0)
  1660.             {
  1661.               as_bad ("Invalid Compare/Subtract Condition");
  1662.               cmpltr = 0;
  1663.             }
  1664.           else
  1665.             {
  1666.               /* Negated condition requires an opcode change.  */
  1667.               opcode |= 1 << 27;
  1668.             }
  1669.         }
  1670.           INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  1671.  
  1672.         /* Handle a compare/subtract condition.  */
  1673.         case 'a':
  1674.           cmpltr = 0;
  1675.           flag = 0;
  1676.           save_s = s;
  1677.           if (*s == ',')
  1678.         {
  1679.           cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 0);
  1680.           if (cmpltr < 0)
  1681.             {
  1682.               flag = 1;
  1683.               s = save_s;
  1684.               cmpltr = pa_parse_neg_cmpsub_cmpltr (&s, 0);
  1685.               if (cmpltr < 0)
  1686.             {
  1687.               as_bad ("Invalid Compare/Subtract Condition");
  1688.             }
  1689.             }
  1690.         }
  1691.           opcode |= cmpltr << 13;
  1692.           INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
  1693.  
  1694.         /* Handle a non-negated add condition.  */
  1695.         case 'd':
  1696.           cmpltr = 0;
  1697.           nullif = 0;
  1698.           flag = 0;
  1699.           if (*s == ',')
  1700.         {
  1701.           s++;
  1702.           name = s;
  1703.           while (*s != ',' && *s != ' ' && *s != '\t')
  1704.             s += 1;
  1705.           c = *s;
  1706.           *s = 0x00;
  1707.           if (strcmp (name, "=") == 0)
  1708.             cmpltr = 1;
  1709.           else if (strcmp (name, "<") == 0)
  1710.             cmpltr = 2;
  1711.           else if (strcmp (name, "<=") == 0)
  1712.             cmpltr = 3;
  1713.           else if (strcasecmp (name, "nuv") == 0)
  1714.             cmpltr = 4;
  1715.           else if (strcasecmp (name, "znv") == 0)
  1716.             cmpltr = 5;
  1717.           else if (strcasecmp (name, "sv") == 0)
  1718.             cmpltr = 6;
  1719.           else if (strcasecmp (name, "od") == 0)
  1720.             cmpltr = 7;
  1721.           else if (strcasecmp (name, "n") == 0)
  1722.             nullif = 1;
  1723.           else if (strcasecmp (name, "tr") == 0)
  1724.             {
  1725.               cmpltr = 0;
  1726.               flag = 1;
  1727.             }
  1728.           else if (strcmp (name, "<>") == 0)
  1729.             {
  1730.               cmpltr = 1;
  1731.               flag = 1;
  1732.             }
  1733.           else if (strcmp (name, ">=") == 0)
  1734.             {
  1735.               cmpltr = 2;
  1736.               flag = 1;
  1737.             }
  1738.           else if (strcmp (name, ">") == 0)
  1739.             {
  1740.               cmpltr = 3;
  1741.               flag = 1;
  1742.             }
  1743.           else if (strcasecmp (name, "uv") == 0)
  1744.             {
  1745.               cmpltr = 4;
  1746.               flag = 1;
  1747.             }
  1748.           else if (strcasecmp (name, "vnz") == 0)
  1749.             {
  1750.               cmpltr = 5;
  1751.               flag = 1;
  1752.             }
  1753.           else if (strcasecmp (name, "nsv") == 0)
  1754.             {
  1755.               cmpltr = 6;
  1756.               flag = 1;
  1757.             }
  1758.           else if (strcasecmp (name, "ev") == 0)
  1759.             {
  1760.               cmpltr = 7;
  1761.               flag = 1;
  1762.             }
  1763.           else
  1764.             as_bad ("Invalid Add Condition: %s", name);
  1765.           *s = c;
  1766.         }
  1767.           nullif = pa_parse_nullif (&s);
  1768.           opcode |= nullif << 1;
  1769.           opcode |= cmpltr << 13;
  1770.           INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
  1771.  
  1772.         /* HANDLE a logical instruction condition.  */
  1773.         case '&':
  1774.           cmpltr = 0;
  1775.           flag = 0;
  1776.           if (*s == ',')
  1777.         {
  1778.           s++;
  1779.           name = s;
  1780.           while (*s != ',' && *s != ' ' && *s != '\t')
  1781.             s += 1;
  1782.           c = *s;
  1783.           *s = 0x00;
  1784.           if (strcmp (name, "=") == 0)
  1785.             cmpltr = 1;
  1786.           else if (strcmp (name, "<") == 0)
  1787.             cmpltr = 2;
  1788.           else if (strcmp (name, "<=") == 0)
  1789.             cmpltr = 3;
  1790.           else if (strcasecmp (name, "od") == 0)
  1791.             cmpltr = 7;
  1792.           else if (strcasecmp (name, "tr") == 0)
  1793.             {
  1794.               cmpltr = 0;
  1795.               flag = 1;
  1796.             }
  1797.           else if (strcmp (name, "<>") == 0)
  1798.             {
  1799.               cmpltr = 1;
  1800.               flag = 1;
  1801.             }
  1802.           else if (strcmp (name, ">=") == 0)
  1803.             {
  1804.               cmpltr = 2;
  1805.               flag = 1;
  1806.             }
  1807.           else if (strcmp (name, ">") == 0)
  1808.             {
  1809.               cmpltr = 3;
  1810.               flag = 1;
  1811.             }
  1812.           else if (strcasecmp (name, "ev") == 0)
  1813.             {
  1814.               cmpltr = 7;
  1815.               flag = 1;
  1816.             }
  1817.           else
  1818.             as_bad ("Invalid Logical Instruction Condition.");
  1819.           *s = c;
  1820.         }
  1821.           opcode |= cmpltr << 13;
  1822.           INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
  1823.  
  1824.         /* Handle a unit instruction condition.  */
  1825.         case 'U':
  1826.           cmpltr = 0;
  1827.           flag = 0;
  1828.           if (*s == ',')
  1829.         {
  1830.           s++;
  1831.           if (strncasecmp (s, "sbz", 3) == 0)
  1832.             {
  1833.               cmpltr = 2;
  1834.               s += 3;
  1835.             }
  1836.           else if (strncasecmp (s, "shz", 3) == 0)
  1837.             {
  1838.               cmpltr = 3;
  1839.               s += 3;
  1840.             }
  1841.           else if (strncasecmp (s, "sdc", 3) == 0)
  1842.             {
  1843.               cmpltr = 4;
  1844.               s += 3;
  1845.             }
  1846.           else if (strncasecmp (s, "sbc", 3) == 0)
  1847.             {
  1848.               cmpltr = 6;
  1849.               s += 3;
  1850.             }
  1851.           else if (strncasecmp (s, "shc", 3) == 0)
  1852.             {
  1853.               cmpltr = 7;
  1854.               s += 3;
  1855.             }
  1856.           else if (strncasecmp (s, "tr", 2) == 0)
  1857.             {
  1858.               cmpltr = 0;
  1859.               flag = 1;
  1860.               s += 2;
  1861.             }
  1862.           else if (strncasecmp (s, "nbz", 3) == 0)
  1863.             {
  1864.               cmpltr = 2;
  1865.               flag = 1;
  1866.               s += 3;
  1867.             }
  1868.           else if (strncasecmp (s, "nhz", 3) == 0)
  1869.             {
  1870.               cmpltr = 3;
  1871.               flag = 1;
  1872.               s += 3;
  1873.             }
  1874.           else if (strncasecmp (s, "ndc", 3) == 0)
  1875.             {
  1876.               cmpltr = 4;
  1877.               flag = 1;
  1878.               s += 3;
  1879.             }
  1880.           else if (strncasecmp (s, "nbc", 3) == 0)
  1881.             {
  1882.               cmpltr = 6;
  1883.               flag = 1;
  1884.               s += 3;
  1885.             }
  1886.           else if (strncasecmp (s, "nhc", 3) == 0)
  1887.             {
  1888.               cmpltr = 7;
  1889.               flag = 1;
  1890.               s += 3;
  1891.             }
  1892.           else
  1893.             as_bad ("Invalid Logical Instruction Condition.");
  1894.         }
  1895.           opcode |= cmpltr << 13;
  1896.           INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
  1897.  
  1898.         /* Handle a shift/extract/deposit condition.  */
  1899.         case '|':
  1900.         case '>':
  1901.           cmpltr = 0;
  1902.           if (*s == ',')
  1903.         {
  1904.           save_s = s++;
  1905.           name = s;
  1906.           while (*s != ',' && *s != ' ' && *s != '\t')
  1907.             s += 1;
  1908.           c = *s;
  1909.           *s = 0x00;
  1910.           if (strcmp (name, "=") == 0)
  1911.             cmpltr = 1;
  1912.           else if (strcmp (name, "<") == 0)
  1913.             cmpltr = 2;
  1914.           else if (strcasecmp (name, "od") == 0)
  1915.             cmpltr = 3;
  1916.           else if (strcasecmp (name, "tr") == 0)
  1917.             cmpltr = 4;
  1918.           else if (strcmp (name, "<>") == 0)
  1919.             cmpltr = 5;
  1920.           else if (strcmp (name, ">=") == 0)
  1921.             cmpltr = 6;
  1922.           else if (strcasecmp (name, "ev") == 0)
  1923.             cmpltr = 7;
  1924.           /* Handle movb,n.  Put things back the way they were.
  1925.              This includes moving s back to where it started.  */
  1926.           else if (strcasecmp (name, "n") == 0 && *args == '|')
  1927.             {
  1928.               *s = c;
  1929.               s = save_s;
  1930.               continue;
  1931.             }
  1932.           else
  1933.             as_bad ("Invalid Shift/Extract/Deposit Condition.");
  1934.           *s = c;
  1935.         }
  1936.           INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  1937.  
  1938.         /* Handle bvb and bb conditions.  */
  1939.         case '~':
  1940.           cmpltr = 0;
  1941.           if (*s == ',')
  1942.         {
  1943.           s++;
  1944.           if (strncmp (s, "<", 1) == 0)
  1945.             {
  1946.               cmpltr = 2;
  1947.               s++;
  1948.             }
  1949.           else if (strncmp (s, ">=", 2) == 0)
  1950.             {
  1951.               cmpltr = 6;
  1952.               s += 2;
  1953.             }
  1954.           else
  1955.             as_bad ("Invalid Bit Branch Condition: %c", *s);
  1956.         }
  1957.           INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  1958.  
  1959.         /* Handle a system control completer.  */
  1960.         case 'Z':
  1961.           if (*s == ',' && (*(s + 1) == 'm' || *(s + 1) == 'M'))
  1962.         {
  1963.           flag = 1;
  1964.           s += 2;
  1965.         }
  1966.           else
  1967.         flag = 0;
  1968.  
  1969.           INSERT_FIELD_AND_CONTINUE (opcode, flag, 5);
  1970.  
  1971.         /* Handle a nullification completer for branch instructions.  */
  1972.         case 'n':
  1973.           nullif = pa_parse_nullif (&s);
  1974.           INSERT_FIELD_AND_CONTINUE (opcode, nullif, 1);
  1975.  
  1976.         /* Handle a nullification completer for copr and spop insns.  */
  1977.         case 'N':
  1978.           nullif = pa_parse_nullif (&s);
  1979.           INSERT_FIELD_AND_CONTINUE (opcode, nullif, 5);
  1980.  
  1981.         /* Handle a 11 bit immediate at 31.  */
  1982.         case 'i':
  1983.           the_insn.field_selector = pa_chk_field_selector (&s);
  1984.           get_expression (s);
  1985.           s = expr_end;
  1986.           if (the_insn.exp.X_op == O_constant)
  1987.         {
  1988.           num = evaluate_absolute (&the_insn);
  1989.           CHECK_FIELD (num, 1023, -1024, 0);
  1990.           low_sign_unext (num, 11, &num);
  1991.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  1992.         }
  1993.           else
  1994.         {
  1995.           if (is_DP_relative (the_insn.exp))
  1996.             the_insn.reloc = R_HPPA_GOTOFF;
  1997.           else if (is_PC_relative (the_insn.exp))
  1998.             the_insn.reloc = R_HPPA_PCREL_CALL;
  1999.           else
  2000.             the_insn.reloc = R_HPPA;
  2001.           the_insn.format = 11;
  2002.           continue;
  2003.         }
  2004.  
  2005.         /* Handle a 14 bit immediate at 31.  */
  2006.         case 'j':
  2007.           the_insn.field_selector = pa_chk_field_selector (&s);
  2008.           get_expression (s);
  2009.           s = expr_end;
  2010.           if (the_insn.exp.X_op == O_constant)
  2011.         {
  2012.           num = evaluate_absolute (&the_insn);
  2013.           CHECK_FIELD (num, 8191, -8192, 0);
  2014.           low_sign_unext (num, 14, &num);
  2015.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2016.         }
  2017.           else
  2018.         {
  2019.           if (is_DP_relative (the_insn.exp))
  2020.             the_insn.reloc = R_HPPA_GOTOFF;
  2021.           else if (is_PC_relative (the_insn.exp))
  2022.             the_insn.reloc = R_HPPA_PCREL_CALL;
  2023.           else
  2024.             the_insn.reloc = R_HPPA;
  2025.           the_insn.format = 14;
  2026.           continue;
  2027.         }
  2028.  
  2029.         /* Handle a 21 bit immediate at 31.  */
  2030.         case 'k':
  2031.           the_insn.field_selector = pa_chk_field_selector (&s);
  2032.           get_expression (s);
  2033.           s = expr_end;
  2034.           if (the_insn.exp.X_op == O_constant)
  2035.         {
  2036.           num = evaluate_absolute (&the_insn);
  2037.           CHECK_FIELD (num >> 11, 1048575, -1048576, 0);
  2038.           dis_assemble_21 (num, &num);
  2039.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2040.         }
  2041.           else
  2042.         {
  2043.           if (is_DP_relative (the_insn.exp))
  2044.             the_insn.reloc = R_HPPA_GOTOFF;
  2045.           else if (is_PC_relative (the_insn.exp))
  2046.             the_insn.reloc = R_HPPA_PCREL_CALL;
  2047.           else
  2048.             the_insn.reloc = R_HPPA;
  2049.           the_insn.format = 21;
  2050.           continue;
  2051.         }
  2052.  
  2053.         /* Handle a 12 bit branch displacement.  */
  2054.         case 'w':
  2055.           the_insn.field_selector = pa_chk_field_selector (&s);
  2056.           get_expression (s);
  2057.           s = expr_end;
  2058.           the_insn.pcrel = 1;
  2059.           if (!strcmp (S_GET_NAME (the_insn.exp.X_add_symbol), "L$0\001"))
  2060.         {
  2061.           unsigned int w1, w, result;
  2062.  
  2063.           num = evaluate_absolute (&the_insn);
  2064.           if (num % 4)
  2065.             {
  2066.               as_bad ("Branch to unaligned address");
  2067.               break;
  2068.             }
  2069.           CHECK_FIELD (num, 8191, -8192, 0);
  2070.           sign_unext ((num - 8) >> 2, 12, &result);
  2071.           dis_assemble_12 (result, &w1, &w);
  2072.           INSERT_FIELD_AND_CONTINUE (opcode, ((w1 << 2) | w), 0);
  2073.         }
  2074.           else
  2075.         {
  2076.           the_insn.reloc = R_HPPA_PCREL_CALL;
  2077.           the_insn.format = 12;
  2078.           the_insn.arg_reloc = last_call_desc.arg_reloc;
  2079.           bzero (&last_call_desc, sizeof (struct call_desc));
  2080.           s = expr_end;
  2081.           continue;
  2082.         }
  2083.  
  2084.         /* Handle a 17 bit branch displacement.  */
  2085.         case 'W':
  2086.           the_insn.field_selector = pa_chk_field_selector (&s);
  2087.           get_expression (s);
  2088.           s = expr_end;
  2089.           the_insn.pcrel = 1;
  2090.           if (!the_insn.exp.X_add_symbol
  2091.           || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
  2092.                   "L$0\001"))
  2093.         {
  2094.           unsigned int w2, w1, w, result;
  2095.  
  2096.           num = evaluate_absolute (&the_insn);
  2097.           if (num % 4)
  2098.             {
  2099.               as_bad ("Branch to unaligned address");
  2100.               break;
  2101.             }
  2102.           CHECK_FIELD (num, 262143, -262144, 0);
  2103.  
  2104.           if (the_insn.exp.X_add_symbol)
  2105.             num -= 8;
  2106.  
  2107.           sign_unext (num >> 2, 17, &result);
  2108.           dis_assemble_17 (result, &w1, &w2, &w);
  2109.           INSERT_FIELD_AND_CONTINUE (opcode,
  2110.                        ((w2 << 2) | (w1 << 16) | w), 0);
  2111.         }
  2112.           else
  2113.         {
  2114.           the_insn.reloc = R_HPPA_PCREL_CALL;
  2115.           the_insn.format = 17;
  2116.           the_insn.arg_reloc = last_call_desc.arg_reloc;
  2117.           bzero (&last_call_desc, sizeof (struct call_desc));
  2118.           continue;
  2119.         }
  2120.  
  2121.         /* Handle an absolute 17 bit branch target.  */
  2122.         case 'z':
  2123.           the_insn.field_selector = pa_chk_field_selector (&s);
  2124.           get_expression (s);
  2125.           s = expr_end;
  2126.           the_insn.pcrel = 0;
  2127.           if (!the_insn.exp.X_add_symbol
  2128.           || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
  2129.                   "L$0\001"))
  2130.         {
  2131.           unsigned int w2, w1, w, result;
  2132.  
  2133.           num = evaluate_absolute (&the_insn);
  2134.           if (num % 4)
  2135.             {
  2136.               as_bad ("Branch to unaligned address");
  2137.               break;
  2138.             }
  2139.           CHECK_FIELD (num, 262143, -262144, 0);
  2140.  
  2141.           if (the_insn.exp.X_add_symbol)
  2142.             num -= 8;
  2143.  
  2144.           sign_unext (num >> 2, 17, &result);
  2145.           dis_assemble_17 (result, &w1, &w2, &w);
  2146.           INSERT_FIELD_AND_CONTINUE (opcode,
  2147.                        ((w2 << 2) | (w1 << 16) | w), 0);
  2148.         }
  2149.           else
  2150.         {
  2151.           the_insn.reloc = R_HPPA_ABS_CALL;
  2152.           the_insn.format = 17;
  2153.           continue;
  2154.         }
  2155.  
  2156.         /* Handle a 5 bit shift count at 26.  */
  2157.         case 'p':
  2158.           num = pa_get_absolute_expression (&the_insn, &s);
  2159.           s = expr_end;
  2160.           CHECK_FIELD (num, 31, 0, 0);
  2161.           INSERT_FIELD_AND_CONTINUE (opcode, 31 - num, 5);
  2162.  
  2163.         /* Handle a 5 bit bit position at 26.  */
  2164.         case 'P':
  2165.           num = pa_get_absolute_expression (&the_insn, &s);
  2166.           s = expr_end;
  2167.           CHECK_FIELD (num, 31, 0, 0);
  2168.           INSERT_FIELD_AND_CONTINUE (opcode, num, 5);
  2169.  
  2170.         /* Handle a 5 bit immediate at 10.  */
  2171.         case 'Q':
  2172.           num = pa_get_absolute_expression (&the_insn, &s);
  2173.           s = expr_end;
  2174.           CHECK_FIELD (num, 31, 0, 0);
  2175.           INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
  2176.  
  2177.         /* Handle a 13 bit immediate at 18.  */
  2178.         case 'A':
  2179.           num = pa_get_absolute_expression (&the_insn, &s);
  2180.           s = expr_end;
  2181.           CHECK_FIELD (num, 8191, 0, 0);
  2182.           INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
  2183.  
  2184.         /* Handle a 26 bit immediate at 31.  */
  2185.         case 'D':
  2186.           num = pa_get_absolute_expression (&the_insn, &s);
  2187.           s = expr_end;
  2188.           CHECK_FIELD (num, 671108864, 0, 0);
  2189.           INSERT_FIELD_AND_CONTINUE (opcode, num, 1);
  2190.  
  2191.         /* Handle a 3 bit SFU identifier at 25.  */
  2192.         case 'f':
  2193.           if (*s++ != ',')
  2194.         as_bad ("Invalid SFU identifier");
  2195.           num = pa_get_absolute_expression (&the_insn, &s);
  2196.           s = expr_end;
  2197.           CHECK_FIELD (num, 7, 0, 0);
  2198.           INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
  2199.  
  2200.         /* Handle a 20 bit SOP field for spop0.  */
  2201.         case 'O':
  2202.           num = pa_get_absolute_expression (&the_insn, &s);
  2203.           s = expr_end;
  2204.           CHECK_FIELD (num, 1048575, 0, 0);
  2205.           num = (num & 0x1f) | ((num & 0x000fffe0) << 6);
  2206.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2207.  
  2208.         /* Handle a 15bit SOP field for spop1.  */
  2209.         case 'o':
  2210.           num = pa_get_absolute_expression (&the_insn, &s);
  2211.           s = expr_end;
  2212.           CHECK_FIELD (num, 32767, 0, 0);
  2213.           INSERT_FIELD_AND_CONTINUE (opcode, num, 11);
  2214.  
  2215.         /* Handle a 10bit SOP field for spop3.  */
  2216.         case '0':
  2217.           num = pa_get_absolute_expression (&the_insn, &s);
  2218.           s = expr_end;
  2219.           CHECK_FIELD (num, 1023, 0, 0);
  2220.           num = (num & 0x1f) | ((num & 0x000003e0) << 6);
  2221.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2222.  
  2223.         /* Handle a 15 bit SOP field for spop2.  */
  2224.         case '1':
  2225.           num = pa_get_absolute_expression (&the_insn, &s);
  2226.           s = expr_end;
  2227.           CHECK_FIELD (num, 32767, 0, 0);
  2228.           num = (num & 0x1f) | ((num & 0x00007fe0) << 6);
  2229.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2230.  
  2231.         /* Handle a 3-bit co-processor ID field.  */
  2232.         case 'u':
  2233.           if (*s++ != ',')
  2234.         as_bad ("Invalid COPR identifier");
  2235.           num = pa_get_absolute_expression (&the_insn, &s);
  2236.           s = expr_end;
  2237.           CHECK_FIELD (num, 7, 0, 0);
  2238.           INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
  2239.  
  2240.         /* Handle a 22bit SOP field for copr.  */
  2241.         case '2':
  2242.           num = pa_get_absolute_expression (&the_insn, &s);
  2243.           s = expr_end;
  2244.           CHECK_FIELD (num, 4194303, 0, 0);
  2245.           num = (num & 0x1f) | ((num & 0x003fffe0) << 4);
  2246.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2247.  
  2248.         /* Handle a source FP operand format completer.  */
  2249.         case 'F':
  2250.           flag = pa_parse_fp_format (&s);
  2251.           the_insn.fpof1 = flag;
  2252.           INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
  2253.  
  2254.         /* Handle a destination FP operand format completer.  */
  2255.         case 'G':
  2256.           /* pa_parse_format needs the ',' prefix.  */
  2257.           s--;
  2258.           flag = pa_parse_fp_format (&s);
  2259.           the_insn.fpof2 = flag;
  2260.           INSERT_FIELD_AND_CONTINUE (opcode, flag, 13);
  2261.  
  2262.         /* Handle FP compare conditions.  */
  2263.         case 'M':
  2264.           cond = pa_parse_fp_cmp_cond (&s);
  2265.           INSERT_FIELD_AND_CONTINUE (opcode, cond, 0);
  2266.  
  2267.         /* Handle L/R register halves like 't'.  */
  2268.         case 'v':
  2269.           {
  2270.         struct pa_89_fp_reg_struct result;
  2271.  
  2272.         pa_parse_number (&s, &result);
  2273.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2274.         opcode |= result.number_part;
  2275.  
  2276.         /* 0x30 opcodes are FP arithmetic operation opcodes
  2277.            and need to be turned into 0x38 opcodes.  This
  2278.            is not necessary for loads/stores.  */
  2279.         if (need_89_opcode (&the_insn, &result)
  2280.             && ((opcode & 0xfc000000) == 0x30000000))
  2281.           opcode |= 1 << 27;
  2282.  
  2283.         INSERT_FIELD_AND_CONTINUE (opcode, result.l_r_select & 1, 6);
  2284.           }
  2285.  
  2286.         /* Handle L/R register halves like 'b'.  */
  2287.         case 'E':
  2288.           {
  2289.         struct pa_89_fp_reg_struct result;
  2290.  
  2291.         pa_parse_number (&s, &result);
  2292.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2293.         opcode |= result.number_part << 21;
  2294.         if (need_89_opcode (&the_insn, &result))
  2295.           {
  2296.             opcode |= (result.l_r_select & 1) << 7;
  2297.             opcode |= 1 << 27;
  2298.           }
  2299.         continue;
  2300.           }
  2301.  
  2302.         /* Handle L/R register halves like 'x'.  */
  2303.         case 'X':
  2304.           {
  2305.         struct pa_89_fp_reg_struct result;
  2306.  
  2307.         pa_parse_number (&s, &result);
  2308.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2309.         opcode |= (result.number_part & 0x1f) << 16;
  2310.         if (need_89_opcode (&the_insn, &result))
  2311.           {
  2312.             opcode |= (result.l_r_select & 1) << 12;
  2313.             opcode |= 1 << 27;
  2314.           }
  2315.         continue;
  2316.           }
  2317.  
  2318.         /* Handle a 5 bit register field at 10.  */
  2319.         case '4':
  2320.           {
  2321.         struct pa_89_fp_reg_struct result;
  2322.  
  2323.         pa_parse_number (&s, &result);
  2324.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2325.         if (the_insn.fpof1 == SGL)
  2326.           {
  2327.             result.number_part &= 0xF;
  2328.             result.number_part |= (result.l_r_select & 1) << 4;
  2329.           }
  2330.         INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 21);
  2331.           }
  2332.  
  2333.         /* Handle a 5 bit register field at 15.  */
  2334.         case '6':
  2335.           {
  2336.         struct pa_89_fp_reg_struct result;
  2337.  
  2338.         pa_parse_number (&s, &result);
  2339.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2340.         if (the_insn.fpof1 == SGL)
  2341.           {
  2342.             result.number_part &= 0xF;
  2343.             result.number_part |= (result.l_r_select & 1) << 4;
  2344.           }
  2345.         INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 16);
  2346.           }
  2347.  
  2348.         /* Handle a 5 bit register field at 31.  */
  2349.         case '7':
  2350.           {
  2351.         struct pa_89_fp_reg_struct result;
  2352.  
  2353.         pa_parse_number (&s, &result);
  2354.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2355.         if (the_insn.fpof1 == SGL)
  2356.           {
  2357.             result.number_part &= 0xF;
  2358.             result.number_part |= (result.l_r_select & 1) << 4;
  2359.           }
  2360.         INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 0);
  2361.           }
  2362.  
  2363.         /* Handle a 5 bit register field at 20.  */
  2364.         case '8':
  2365.           {
  2366.         struct pa_89_fp_reg_struct result;
  2367.  
  2368.         pa_parse_number (&s, &result);
  2369.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2370.         if (the_insn.fpof1 == SGL)
  2371.           {
  2372.             result.number_part &= 0xF;
  2373.             result.number_part |= (result.l_r_select & 1) << 4;
  2374.           }
  2375.         INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 11);
  2376.           }
  2377.  
  2378.         /* Handle a 5 bit register field at 25.  */
  2379.         case '9':
  2380.           {
  2381.         struct pa_89_fp_reg_struct result;
  2382.  
  2383.         pa_parse_number (&s, &result);
  2384.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2385.         if (the_insn.fpof1 == SGL)
  2386.           {
  2387.             result.number_part &= 0xF;
  2388.             result.number_part |= (result.l_r_select & 1) << 4;
  2389.           }
  2390.         INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 6);
  2391.           }
  2392.  
  2393.         /* Handle a floating point operand format at 26.
  2394.            Only allows single and double precision.  */
  2395.         case 'H':
  2396.           flag = pa_parse_fp_format (&s);
  2397.           switch (flag)
  2398.         {
  2399.         case SGL:
  2400.           opcode |= 0x20;
  2401.         case DBL:
  2402.           the_insn.fpof1 = flag;
  2403.           continue;
  2404.  
  2405.         case QUAD:
  2406.         case ILLEGAL_FMT:
  2407.         default:
  2408.           as_bad ("Invalid Floating Point Operand Format.");
  2409.         }
  2410.           break;
  2411.  
  2412.         default:
  2413.           abort ();
  2414.         }
  2415.       break;
  2416.     }
  2417.  
  2418.       /* Check if the args matched.  */
  2419.       if (match == FALSE)
  2420.     {
  2421.       if (&insn[1] - pa_opcodes < NUMOPCODES
  2422.           && !strcmp (insn->name, insn[1].name))
  2423.         {
  2424.           ++insn;
  2425.           s = argstart;
  2426.           continue;
  2427.         }
  2428.       else
  2429.         {
  2430.           as_bad ("Invalid operands %s", error_message);
  2431.           return;
  2432.         }
  2433.     }
  2434.       break;
  2435.     }
  2436.  
  2437.   the_insn.opcode = opcode;
  2438. }
  2439.  
  2440. /* Turn a string in input_line_pointer into a floating point constant of type
  2441.    type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  2442.    emitted is stored in *sizeP .  An error message or NULL is returned.  */
  2443.  
  2444. #define MAX_LITTLENUMS 6
  2445.  
  2446. char *
  2447. md_atof (type, litP, sizeP)
  2448.      char type;
  2449.      char *litP;
  2450.      int *sizeP;
  2451. {
  2452.   int prec;
  2453.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  2454.   LITTLENUM_TYPE *wordP;
  2455.   char *t;
  2456.  
  2457.   switch (type)
  2458.     {
  2459.  
  2460.     case 'f':
  2461.     case 'F':
  2462.     case 's':
  2463.     case 'S':
  2464.       prec = 2;
  2465.       break;
  2466.  
  2467.     case 'd':
  2468.     case 'D':
  2469.     case 'r':
  2470.     case 'R':
  2471.       prec = 4;
  2472.       break;
  2473.  
  2474.     case 'x':
  2475.     case 'X':
  2476.       prec = 6;
  2477.       break;
  2478.  
  2479.     case 'p':
  2480.     case 'P':
  2481.       prec = 6;
  2482.       break;
  2483.  
  2484.     default:
  2485.       *sizeP = 0;
  2486.       return "Bad call to MD_ATOF()";
  2487.     }
  2488.   t = atof_ieee (input_line_pointer, type, words);
  2489.   if (t)
  2490.     input_line_pointer = t;
  2491.   *sizeP = prec * sizeof (LITTLENUM_TYPE);
  2492.   for (wordP = words; prec--;)
  2493.     {
  2494.       md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
  2495.       litP += sizeof (LITTLENUM_TYPE);
  2496.     }
  2497.   return NULL;
  2498. }
  2499.  
  2500. /* Write out big-endian.  */
  2501.  
  2502. void
  2503. md_number_to_chars (buf, val, n)
  2504.      char *buf;
  2505.      valueT val;
  2506.      int n;
  2507. {
  2508.   number_to_chars_bigendian (buf, val, n);
  2509. }
  2510.  
  2511. /* Translate internal representation of relocation info to BFD target
  2512.    format.  */
  2513.  
  2514. arelent **
  2515. tc_gen_reloc (section, fixp)
  2516.      asection *section;
  2517.      fixS *fixp;
  2518. {
  2519.   arelent *reloc;
  2520.   struct hppa_fix_struct *hppa_fixp;
  2521.   bfd_reloc_code_real_type code;
  2522.   static arelent *no_relocs = NULL;
  2523.   arelent **relocs;
  2524.   bfd_reloc_code_real_type **codes;
  2525.   int n_relocs;
  2526.   int i;
  2527.  
  2528.   hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
  2529.   if (fixp->fx_addsy == 0)
  2530.     return &no_relocs;
  2531.   assert (hppa_fixp != 0);
  2532.   assert (section != 0);
  2533.  
  2534.   reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
  2535.   assert (reloc != 0);
  2536.  
  2537.   reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  2538.   codes = (bfd_reloc_code_real_type **) hppa_gen_reloc_type (stdoutput,
  2539.                    fixp->fx_r_type,
  2540.                    hppa_fixp->fx_r_format,
  2541.                    hppa_fixp->fx_r_field);
  2542.  
  2543.   for (n_relocs = 0; codes[n_relocs]; n_relocs++)
  2544.     ;
  2545.  
  2546.   relocs = (arelent **)
  2547.     bfd_alloc_by_size_t (stdoutput, sizeof (arelent *) * n_relocs + 1);
  2548.   assert (relocs != 0);
  2549.  
  2550.   reloc = (arelent *) bfd_alloc_by_size_t (stdoutput,
  2551.                        sizeof (arelent) * n_relocs);
  2552.   if (n_relocs > 0)
  2553.     assert (reloc != 0);
  2554.  
  2555.   for (i = 0; i < n_relocs; i++)
  2556.     relocs[i] = &reloc[i];
  2557.  
  2558.   relocs[n_relocs] = NULL;
  2559.  
  2560. #ifdef OBJ_ELF
  2561.   switch (fixp->fx_r_type)
  2562.     {
  2563.     default:
  2564.       assert (n_relocs == 1);
  2565.  
  2566.       code = *codes[0];
  2567.  
  2568.       reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  2569.       reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
  2570.       reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2571.       reloc->addend = 0;    /* default */
  2572.  
  2573.       assert (reloc->howto && code == reloc->howto->type);
  2574.  
  2575.       /* Now, do any processing that is dependent on the relocation type.  */
  2576.       switch (code)
  2577.     {
  2578.     case R_PARISC_DLTREL21L:
  2579.     case R_PARISC_DLTREL14R:
  2580.     case R_PARISC_DLTREL14F:
  2581.     case R_PARISC_PLABEL32:
  2582.     case R_PARISC_PLABEL21L:
  2583.     case R_PARISC_PLABEL14R:
  2584.       /* For plabel relocations, the addend of the
  2585.          relocation should be either 0 (no static link) or 2
  2586.          (static link required).
  2587.  
  2588.          FIXME: We always assume no static link!
  2589.  
  2590.          We also slam a zero addend into the DLT relative relocs;
  2591.          it doesn't make a lot of sense to use any addend since
  2592.          it gets you a different (eg unknown) DLT entry.  */
  2593.       reloc->addend = 0;
  2594.       break;
  2595.  
  2596.     case R_PARISC_PCREL21L:
  2597.     case R_PARISC_PCREL17R:
  2598.     case R_PARISC_PCREL17F:
  2599.     case R_PARISC_PCREL17C:
  2600.     case R_PARISC_PCREL14R:
  2601.     case R_PARISC_PCREL14F:
  2602.       /* The constant is stored in the instruction.  */
  2603.       reloc->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
  2604.       break;
  2605.     default:
  2606.       reloc->addend = fixp->fx_offset;
  2607.       break;
  2608.     }
  2609.       break;
  2610.     }
  2611. #else /* OBJ_SOM */
  2612.  
  2613.   /* Walk over reach relocation returned by the BFD backend.  */
  2614.   for (i = 0; i < n_relocs; i++)
  2615.     {
  2616.       code = *codes[i];
  2617.  
  2618.       relocs[i]->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  2619.       relocs[i]->howto = bfd_reloc_type_lookup (stdoutput, code);
  2620.       relocs[i]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2621.  
  2622.       switch (code)
  2623.     {
  2624.     case R_PCREL_CALL:
  2625.     case R_ABS_CALL:
  2626.       relocs[i]->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
  2627.       break;
  2628.  
  2629.     case R_DLT_REL:
  2630.     case R_DATA_PLABEL:
  2631.     case R_CODE_PLABEL:
  2632.       /* For plabel relocations, the addend of the
  2633.          relocation should be either 0 (no static link) or 2
  2634.          (static link required).
  2635.  
  2636.          FIXME: We always assume no static link!
  2637.  
  2638.          We also slam a zero addend into the DLT relative relocs;
  2639.          it doesn't make a lot of sense to use any addend since
  2640.          it gets you a different (eg unknown) DLT entry.  */
  2641.       relocs[i]->addend = 0;
  2642.       break;
  2643.  
  2644.     case R_N_MODE:
  2645.     case R_S_MODE:
  2646.     case R_D_MODE:
  2647.     case R_R_MODE:
  2648.     case R_FSEL:
  2649.     case R_LSEL:
  2650.     case R_RSEL:
  2651.       /* There is no symbol or addend associated with these fixups.  */
  2652.       relocs[i]->sym_ptr_ptr = &dummy_symbol->bsym;
  2653.       relocs[i]->addend = 0;
  2654.       break;
  2655.  
  2656.     case R_ENTRY:
  2657.     case R_EXIT:
  2658.       /* There is no symbol associated with these fixups.  */
  2659.       relocs[i]->sym_ptr_ptr = &dummy_symbol->bsym;
  2660.       relocs[i]->addend = fixp->fx_offset;
  2661.       break;
  2662.  
  2663.     default:
  2664.       relocs[i]->addend = fixp->fx_offset;
  2665.     }
  2666.     }
  2667. #endif
  2668.  
  2669.   return relocs;
  2670. }
  2671.  
  2672. /* Process any machine dependent frag types.  */
  2673.  
  2674. void
  2675. md_convert_frag (abfd, sec, fragP)
  2676.      register bfd *abfd;
  2677.      register asection *sec;
  2678.      register fragS *fragP;
  2679. {
  2680.   unsigned int address;
  2681.  
  2682.   if (fragP->fr_type == rs_machine_dependent)
  2683.     {
  2684.       switch ((int) fragP->fr_subtype)
  2685.     {
  2686.     case 0:
  2687.       fragP->fr_type = rs_fill;
  2688.       know (fragP->fr_var == 1);
  2689.       know (fragP->fr_next);
  2690.       address = fragP->fr_address + fragP->fr_fix;
  2691.       if (address % fragP->fr_offset)
  2692.         {
  2693.           fragP->fr_offset =
  2694.         fragP->fr_next->fr_address
  2695.         - fragP->fr_address
  2696.         - fragP->fr_fix;
  2697.         }
  2698.       else
  2699.         fragP->fr_offset = 0;
  2700.       break;
  2701.     }
  2702.     }
  2703. }
  2704.  
  2705. /* Round up a section size to the appropriate boundary. */
  2706.  
  2707. valueT
  2708. md_section_align (segment, size)
  2709.      asection *segment;
  2710.      valueT size;
  2711. {
  2712.   int align = bfd_get_section_alignment (stdoutput, segment);
  2713.   int align2 = (1 << align) - 1;
  2714.  
  2715.   return (size + align2) & ~align2;
  2716. }
  2717.  
  2718. /* Create a short jump from FROM_ADDR to TO_ADDR.  Not used on the PA.  */
  2719. void
  2720. md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
  2721.      char *ptr;
  2722.      addressT from_addr, to_addr;
  2723.      fragS *frag;
  2724.      symbolS *to_symbol;
  2725. {
  2726.   fprintf (stderr, "pa_create_short_jmp\n");
  2727.   abort ();
  2728. }
  2729.  
  2730. /* Create a long jump from FROM_ADDR to TO_ADDR.  Not used on the PA.  */
  2731. void
  2732. md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
  2733.      char *ptr;
  2734.      addressT from_addr, to_addr;
  2735.      fragS *frag;
  2736.      symbolS *to_symbol;
  2737. {
  2738.   fprintf (stderr, "pa_create_long_jump\n");
  2739.   abort ();
  2740. }
  2741.  
  2742. /* Return the approximate size of a frag before relaxation has occurred.  */
  2743. int
  2744. md_estimate_size_before_relax (fragP, segment)
  2745.      register fragS *fragP;
  2746.      asection *segment;
  2747. {
  2748.   int size;
  2749.  
  2750.   size = 0;
  2751.  
  2752.   while ((fragP->fr_fix + size) % fragP->fr_offset)
  2753.     size++;
  2754.  
  2755.   return size;
  2756. }
  2757.  
  2758. CONST char *md_shortopts = "";
  2759. struct option md_longopts[] = {
  2760.   {NULL, no_argument, NULL, 0}
  2761. };
  2762. size_t md_longopts_size = sizeof(md_longopts);
  2763.  
  2764. int
  2765. md_parse_option (c, arg)
  2766.      int c;
  2767.      char *arg;
  2768. {
  2769.   return 0;
  2770. }
  2771.  
  2772. void
  2773. md_show_usage (stream)
  2774.      FILE *stream;
  2775. {
  2776. }
  2777.  
  2778. /* We have no need to default values of symbols.  */
  2779.  
  2780. symbolS *
  2781. md_undefined_symbol (name)
  2782.      char *name;
  2783. {
  2784.   return 0;
  2785. }
  2786.  
  2787. /* Parse an operand that is machine-specific.
  2788.    We just return without modifying the expression as we have nothing
  2789.    to do on the PA.  */
  2790.  
  2791. void
  2792. md_operand (expressionP)
  2793.      expressionS *expressionP;
  2794. {
  2795. }
  2796.  
  2797. /* Apply a fixup to an instruction.  */
  2798.  
  2799. int
  2800. md_apply_fix (fixP, valp)
  2801.      fixS *fixP;
  2802.      valueT *valp;
  2803. {
  2804.   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
  2805.   struct hppa_fix_struct *hppa_fixP;
  2806.   long new_val, result;
  2807.   unsigned int w1, w2, w;
  2808.  
  2809.   hppa_fixP = (struct hppa_fix_struct *) fixP->tc_fix_data;
  2810.   /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
  2811.      never be "applied" (they are just markers).  */
  2812. #ifdef OBJ_SOM
  2813.   if (fixP->fx_r_type == R_HPPA_ENTRY
  2814.       || fixP->fx_r_type == R_HPPA_EXIT)
  2815.     return;
  2816. #endif
  2817.  
  2818.   /* There should have been an HPPA specific fixup associated
  2819.      with the GAS fixup.  */
  2820.   if (hppa_fixP)
  2821.     {
  2822.       unsigned long buf_wd = bfd_get_32 (stdoutput, buf);
  2823.       unsigned char fmt = bfd_hppa_insn2fmt (buf_wd);
  2824.  
  2825.       /* If there is a symbol associated with this fixup, then it's something
  2826.      which will need a SOM relocation (except for some PC-relative relocs).
  2827.      In such cases we should treat the "val" or "addend" as zero since it
  2828.      will be added in as needed from fx_offset in tc_gen_reloc.  */
  2829.       if (fixP->fx_addsy != NULL
  2830.       || fixP->fx_r_type == R_HPPA_NONE)
  2831.     new_val = ((fmt == 12 || fmt == 17) ? 8 : 0);
  2832.       else
  2833.     new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field);
  2834.  
  2835.       /* Handle pc-relative exceptions from above.  */
  2836. #define stub_needed(CALLER, CALLEE) \
  2837.   ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
  2838.       if ((fmt == 12 || fmt == 17)
  2839.       && fixP->fx_addsy
  2840.       && fixP->fx_pcrel
  2841.       && !stub_needed (((obj_symbol_type *)
  2842.                 fixP->fx_addsy->bsym)->tc_data.hppa_arg_reloc,
  2843.                hppa_fixP->fx_arg_reloc)
  2844.       && S_GET_SEGMENT (fixP->fx_addsy) == hppa_fixP->segment
  2845.       && !(fixP->fx_subsy
  2846.            && S_GET_SEGMENT (fixP->fx_subsy) != hppa_fixP->segment))
  2847.           
  2848.     new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field);
  2849. #undef stub_needed
  2850.     
  2851.       switch (fmt)
  2852.     {
  2853.     /* Handle all opcodes with the 'j' operand type.  */
  2854.     case 14:
  2855.       CHECK_FIELD (new_val, 8191, -8192, 0);
  2856.  
  2857.       /* Mask off 14 bits to be changed.  */
  2858.       bfd_put_32 (stdoutput,
  2859.               bfd_get_32 (stdoutput, buf) & 0xffffc000,
  2860.               buf);
  2861.       low_sign_unext (new_val, 14, &result);
  2862.       break;
  2863.  
  2864.     /* Handle all opcodes with the 'k' operand type.  */
  2865.     case 21:
  2866.       CHECK_FIELD (new_val, 2097152, 0, 0);
  2867.  
  2868.       /* Mask off 21 bits to be changed.  */
  2869.       bfd_put_32 (stdoutput,
  2870.               bfd_get_32 (stdoutput, buf) & 0xffe00000,
  2871.               buf);
  2872.       dis_assemble_21 (new_val, &result);
  2873.       break;
  2874.  
  2875.     /* Handle all the opcodes with the 'i' operand type.  */
  2876.     case 11:
  2877.       CHECK_FIELD (new_val, 1023, -1023, 0);
  2878.  
  2879.       /* Mask off 11 bits to be changed.  */
  2880.       bfd_put_32 (stdoutput,
  2881.               bfd_get_32 (stdoutput, buf) & 0xffff800,
  2882.               buf);
  2883.       low_sign_unext (new_val, 11, &result);
  2884.       break;
  2885.  
  2886.     /* Handle all the opcodes with the 'w' operand type.  */
  2887.     case 12:
  2888.       CHECK_FIELD (new_val, 8191, -8192, 0)
  2889.  
  2890.       /* Mask off 11 bits to be changed.  */
  2891.         sign_unext ((new_val - 8) >> 2, 12, &result);
  2892.       bfd_put_32 (stdoutput,
  2893.               bfd_get_32 (stdoutput, buf) & 0xffffe002,
  2894.               buf);
  2895.  
  2896.       dis_assemble_12 (result, &w1, &w);
  2897.       result = ((w1 << 2) | w);
  2898.       break;
  2899.  
  2900.     /* Handle some of the opcodes with the 'W' operand type.  */
  2901.     case 17:
  2902.       CHECK_FIELD (new_val, 262143, -262144, 0);
  2903.  
  2904.       /* Mask off 17 bits to be changed.  */
  2905.       bfd_put_32 (stdoutput,
  2906.               bfd_get_32 (stdoutput, buf) & 0xffe0e002,
  2907.               buf);
  2908.       sign_unext ((new_val - 8) >> 2, 17, &result);
  2909.       dis_assemble_17 (result, &w1, &w2, &w);
  2910.       result = ((w2 << 2) | (w1 << 16) | w);
  2911.       break;
  2912.  
  2913.     case 32:
  2914.       result = 0;
  2915.       bfd_put_32 (stdoutput, new_val, buf);
  2916.       break;
  2917.  
  2918.     default:
  2919.       as_bad ("Unknown relocation encountered in md_apply_fix.");
  2920.       return;
  2921.     }
  2922.  
  2923.       /* Insert the relocation.  */
  2924.       bfd_put_32 (stdoutput, bfd_get_32 (stdoutput, buf) | result, buf);
  2925.       return;
  2926.     }
  2927.   else
  2928.     {
  2929.       printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
  2930.           (unsigned int) fixP, fixP->fx_r_type);
  2931.       return;
  2932.     }
  2933. }
  2934.  
  2935. /* Exactly what point is a PC-relative offset relative TO?
  2936.    On the PA, they're relative to the address of the offset.  */
  2937.  
  2938. long
  2939. md_pcrel_from (fixP)
  2940.      fixS *fixP;
  2941. {
  2942.   return fixP->fx_where + fixP->fx_frag->fr_address;
  2943. }
  2944.  
  2945. /* Return nonzero if the input line pointer is at the end of
  2946.    a statement.  */
  2947.  
  2948. static int
  2949. is_end_of_statement ()
  2950. {
  2951.   return ((*input_line_pointer == '\n')
  2952.       || (*input_line_pointer == ';')
  2953.       || (*input_line_pointer == '!'));
  2954. }
  2955.  
  2956. /* Read a number from S.  The number might come in one of many forms,
  2957.    the most common will be a hex or decimal constant, but it could be
  2958.    a pre-defined register (Yuk!), or an absolute symbol.
  2959.  
  2960.    Return a number or -1 for failure.
  2961.  
  2962.    When parsing PA-89 FP register numbers RESULT will be
  2963.    the address of a structure to return information about
  2964.    L/R half of FP registers, store results there as appropriate.
  2965.  
  2966.    pa_parse_number can not handle negative constants and will fail
  2967.    horribly if it is passed such a constant.  */
  2968.  
  2969. static int
  2970. pa_parse_number (s, result)
  2971.      char **s;
  2972.      struct pa_89_fp_reg_struct *result;
  2973. {
  2974.   int num;
  2975.   char *name;
  2976.   char c;
  2977.   symbolS *sym;
  2978.   int status;
  2979.   char *p = *s;
  2980.  
  2981.   /* Skip whitespace before the number.  */
  2982.   while (*p == ' ' || *p == '\t')
  2983.     p = p + 1;
  2984.  
  2985.   /* Store info in RESULT if requested by caller.  */
  2986.   if (result)
  2987.     {
  2988.       result->number_part = -1;
  2989.       result->l_r_select = -1;
  2990.     }
  2991.   num = -1;
  2992.  
  2993.   if (isdigit (*p))
  2994.     {
  2995.       /* Looks like a number.  */
  2996.       num = 0;
  2997.  
  2998.       if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X'))
  2999.     {
  3000.       /* The number is specified in hex.  */
  3001.       p += 2;
  3002.       while (isdigit (*p) || ((*p >= 'a') && (*p <= 'f'))
  3003.          || ((*p >= 'A') && (*p <= 'F')))
  3004.         {
  3005.           if (isdigit (*p))
  3006.         num = num * 16 + *p - '0';
  3007.           else if (*p >= 'a' && *p <= 'f')
  3008.         num = num * 16 + *p - 'a' + 10;
  3009.           else
  3010.         num = num * 16 + *p - 'A' + 10;
  3011.           ++p;
  3012.         }
  3013.     }
  3014.       else
  3015.     {
  3016.       /* The number is specified in decimal.  */
  3017.       while (isdigit (*p))
  3018.         {
  3019.           num = num * 10 + *p - '0';
  3020.           ++p;
  3021.         }
  3022.     }
  3023.  
  3024.       /* Store info in RESULT if requested by the caller.  */
  3025.       if (result)
  3026.     {
  3027.       result->number_part = num;
  3028.  
  3029.       if (IS_R_SELECT (p))
  3030.         {
  3031.           result->l_r_select = 1;
  3032.           ++p;
  3033.         }
  3034.       else if (IS_L_SELECT (p))
  3035.         {
  3036.           result->l_r_select = 0;
  3037.           ++p;
  3038.         }
  3039.       else
  3040.         result->l_r_select = 0;
  3041.     }
  3042.     }
  3043.   else if (*p == '%')
  3044.     {
  3045.       /* The number might be a predefined register.  */
  3046.       num = 0;
  3047.       name = p;
  3048.       p++;
  3049.       c = *p;
  3050.       /* Tege hack: Special case for general registers as the general
  3051.          code makes a binary search with case translation, and is VERY
  3052.          slow. */
  3053.       if (c == 'r')
  3054.     {
  3055.       p++;
  3056.       if (*p == 'e' && *(p + 1) == 't'
  3057.           && (*(p + 2) == '0' || *(p + 2) == '1'))
  3058.         {
  3059.           p += 2;
  3060.           num = *p - '0' + 28;
  3061.           p++;
  3062.         }
  3063.       else if (*p == 'p')
  3064.         {
  3065.           num = 2;
  3066.           p++;
  3067.         }
  3068.       else if (!isdigit (*p))
  3069.         {
  3070.           if (print_errors)
  3071.         as_bad ("Undefined register: '%s'.", name);
  3072.           num = -1;
  3073.         }
  3074.       else
  3075.         {
  3076.           do
  3077.         num = num * 10 + *p++ - '0';
  3078.           while (isdigit (*p));
  3079.         }
  3080.     }
  3081.       else
  3082.     {
  3083.       /* Do a normal register search.  */
  3084.       while (is_part_of_name (c))
  3085.         {
  3086.           p = p + 1;
  3087.           c = *p;
  3088.         }
  3089.       *p = 0;
  3090.       status = reg_name_search (name);
  3091.       if (status >= 0)
  3092.         num = status;
  3093.       else
  3094.         {
  3095.           if (print_errors)
  3096.         as_bad ("Undefined register: '%s'.", name);
  3097.           num = -1;
  3098.         }
  3099.       *p = c;
  3100.     }
  3101.  
  3102.       /* Store info in RESULT if requested by caller.  */
  3103.       if (result)
  3104.     {
  3105.       result->number_part = num;
  3106.       if (IS_R_SELECT (p - 1))
  3107.         result->l_r_select = 1;
  3108.       else if (IS_L_SELECT (p - 1))
  3109.         result->l_r_select = 0;
  3110.       else
  3111.         result->l_r_select = 0;
  3112.     }
  3113.     }
  3114.   else
  3115.     {
  3116.       /* And finally, it could be a symbol in the absolute section which
  3117.          is effectively a constant.  */
  3118.       num = 0;
  3119.       name = p;
  3120.       c = *p;
  3121.       while (is_part_of_name (c))
  3122.     {
  3123.       p = p + 1;
  3124.       c = *p;
  3125.     }
  3126.       *p = 0;
  3127.       if ((sym = symbol_find (name)) != NULL)
  3128.     {
  3129.       if (S_GET_SEGMENT (sym) == &bfd_abs_section)
  3130.         num = S_GET_VALUE (sym);
  3131.       else
  3132.         {
  3133.           if (print_errors)
  3134.         as_bad ("Non-absolute symbol: '%s'.", name);
  3135.           num = -1;
  3136.         }
  3137.     }
  3138.       else
  3139.     {
  3140.       /* There is where we'd come for an undefined symbol
  3141.          or for an empty string.  For an empty string we
  3142.          will return zero.  That's a concession made for
  3143.          compatability with the braindamaged HP assemblers.  */
  3144.       if (*name == 0)
  3145.         num = 0;
  3146.       else
  3147.         {
  3148.           if (print_errors)
  3149.         as_bad ("Undefined absolute constant: '%s'.", name);
  3150.           num = -1;
  3151.         }
  3152.     }
  3153.       *p = c;
  3154.  
  3155.       /* Store info in RESULT if requested by caller.  */
  3156.       if (result)
  3157.     {
  3158.       result->number_part = num;
  3159.       if (IS_R_SELECT (p - 1))
  3160.         result->l_r_select = 1;
  3161.       else if (IS_L_SELECT (p - 1))
  3162.         result->l_r_select = 0;
  3163.       else
  3164.         result->l_r_select = 0;
  3165.     }
  3166.     }
  3167.  
  3168.   *s = p;
  3169.   return num;
  3170. }
  3171.  
  3172. #define REG_NAME_CNT    (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
  3173.  
  3174. /* Given NAME, find the register number associated with that name, return
  3175.    the integer value associated with the given name or -1 on failure.  */
  3176.  
  3177. static int
  3178. reg_name_search (name)
  3179.      char *name;
  3180. {
  3181.   int middle, low, high;
  3182.   int cmp;
  3183.  
  3184.   low = 0;
  3185.   high = REG_NAME_CNT - 1;
  3186.  
  3187.   do
  3188.     {
  3189.       middle = (low + high) / 2;
  3190.       cmp = strcasecmp (name, pre_defined_registers[middle].name);
  3191.       if (cmp < 0)
  3192.     high = middle - 1;
  3193.       else if (cmp > 0)
  3194.     low = middle + 1;
  3195.       else
  3196.     return pre_defined_registers[middle].value;
  3197.     }
  3198.   while (low <= high);
  3199.  
  3200.   return -1;
  3201. }
  3202.  
  3203.  
  3204. /* Return nonzero if the given INSN and L/R information will require
  3205.    a new PA-89 opcode.  */
  3206.  
  3207. static int
  3208. need_89_opcode (insn, result)
  3209.      struct pa_it *insn;
  3210.      struct pa_89_fp_reg_struct *result;
  3211. {
  3212.   if (result->l_r_select == 1 && !(insn->fpof1 == DBL && insn->fpof2 == DBL))
  3213.     return TRUE;
  3214.   else
  3215.     return FALSE;
  3216. }
  3217.  
  3218. /* Parse a condition for a fcmp instruction.  Return the numerical
  3219.    code associated with the condition.  */
  3220.  
  3221. static int
  3222. pa_parse_fp_cmp_cond (s)
  3223.      char **s;
  3224. {
  3225.   int cond, i;
  3226.  
  3227.   cond = 0;
  3228.  
  3229.   for (i = 0; i < 32; i++)
  3230.     {
  3231.       if (strncasecmp (*s, fp_cond_map[i].string,
  3232.                strlen (fp_cond_map[i].string)) == 0)
  3233.     {
  3234.       cond = fp_cond_map[i].cond;
  3235.       *s += strlen (fp_cond_map[i].string);
  3236.       /* If not a complete match, back up the input string and
  3237.          report an error.  */
  3238.       if (**s != ' ' && **s != '\t')
  3239.         {
  3240.           *s -= strlen (fp_cond_map[i].string);
  3241.           break;
  3242.         }
  3243.       while (**s == ' ' || **s == '\t')
  3244.         *s = *s + 1;
  3245.       return cond;
  3246.     }
  3247.     }
  3248.  
  3249.   as_bad ("Invalid FP Compare Condition: %s", *s);
  3250.  
  3251.   /* Advance over the bogus completer.  */
  3252.   while (**s != ',' && **s != ' ' && **s != '\t')
  3253.     *s += 1;
  3254.  
  3255.   return 0;
  3256. }
  3257.  
  3258. /* Parse an FP operand format completer returning the completer
  3259.    type.  */
  3260.  
  3261. static fp_operand_format
  3262. pa_parse_fp_format (s)
  3263.      char **s;
  3264. {
  3265.   int format;
  3266.  
  3267.   format = SGL;
  3268.   if (**s == ',')
  3269.     {
  3270.       *s += 1;
  3271.       if (strncasecmp (*s, "sgl", 3) == 0)
  3272.     {
  3273.       format = SGL;
  3274.       *s += 4;
  3275.     }
  3276.       else if (strncasecmp (*s, "dbl", 3) == 0)
  3277.     {
  3278.       format = DBL;
  3279.       *s += 4;
  3280.     }
  3281.       else if (strncasecmp (*s, "quad", 4) == 0)
  3282.     {
  3283.       format = QUAD;
  3284.       *s += 5;
  3285.     }
  3286.       else
  3287.     {
  3288.       format = ILLEGAL_FMT;
  3289.       as_bad ("Invalid FP Operand Format: %3s", *s);
  3290.     }
  3291.     }
  3292.  
  3293.   return format;
  3294. }
  3295.  
  3296. /* Convert from a selector string into a selector type.  */
  3297.  
  3298. static int
  3299. pa_chk_field_selector (str)
  3300.      char **str;
  3301. {
  3302.   int middle, low, high;
  3303.   int cmp;
  3304.   char name[3];
  3305.  
  3306.   /* Read past any whitespace.  */
  3307.   /* FIXME: should we read past newlines and formfeeds??? */
  3308.   while (**str == ' ' || **str == '\t' || **str == '\n' || **str == '\f')
  3309.     *str = *str + 1;
  3310.  
  3311.   if ((*str)[1] == '\'' || (*str)[1] == '%')
  3312.     name[0] = tolower ((*str)[0]),
  3313.     name[1] = 0;
  3314.   else if ((*str)[2] == '\'' || (*str)[2] == '%')
  3315.     name[0] = tolower ((*str)[0]),
  3316.     name[1] = tolower ((*str)[1]),
  3317.     name[2] = 0;
  3318.   else
  3319.     return e_fsel;
  3320.  
  3321.   low = 0;
  3322.   high = sizeof (selector_table) / sizeof (struct selector_entry) - 1;
  3323.  
  3324.   do
  3325.     {
  3326.       middle = (low + high) / 2;
  3327.       cmp = strcmp (name, selector_table[middle].prefix);
  3328.       if (cmp < 0)
  3329.     high = middle - 1;
  3330.       else if (cmp > 0)
  3331.     low = middle + 1;
  3332.       else
  3333.     {
  3334.       *str += strlen (name) + 1;
  3335.       return selector_table[middle].field_selector;
  3336.     }
  3337.     }
  3338.   while (low <= high);
  3339.  
  3340.   return e_fsel;
  3341. }
  3342.  
  3343. /* Mark (via expr_end) the end of an expression (I think).  FIXME.  */
  3344.  
  3345. static int
  3346. get_expression (str)
  3347.      char *str;
  3348. {
  3349.   char *save_in;
  3350.   asection *seg;
  3351.  
  3352.   save_in = input_line_pointer;
  3353.   input_line_pointer = str;
  3354.   seg = expression (&the_insn.exp);
  3355.   if (!(seg == absolute_section
  3356.     || seg == undefined_section
  3357.     || SEG_NORMAL (seg)))
  3358.     {
  3359.       as_warn ("Bad segment in expression.");
  3360.       expr_end = input_line_pointer;
  3361.       input_line_pointer = save_in;
  3362.       return 1;
  3363.     }
  3364.   expr_end = input_line_pointer;
  3365.   input_line_pointer = save_in;
  3366.   return 0;
  3367. }
  3368.  
  3369. /* Mark (via expr_end) the end of an absolute expression.  FIXME. */
  3370. static int
  3371. pa_get_absolute_expression (insn, strp)
  3372.      struct pa_it *insn;
  3373.      char **strp;
  3374. {
  3375.   char *save_in;
  3376.  
  3377.   insn->field_selector = pa_chk_field_selector (strp);
  3378.   save_in = input_line_pointer;
  3379.   input_line_pointer = *strp;
  3380.   expression (&insn->exp);
  3381.   if (insn->exp.X_op != O_constant)
  3382.     {
  3383.       as_bad ("Bad segment (should be absolute).");
  3384.       expr_end = input_line_pointer;
  3385.       input_line_pointer = save_in;
  3386.       return 0;
  3387.     }
  3388.   expr_end = input_line_pointer;
  3389.   input_line_pointer = save_in;
  3390.   return evaluate_absolute (insn);
  3391. }
  3392.  
  3393. /* Evaluate an absolute expression EXP which may be modified by
  3394.    the selector FIELD_SELECTOR.  Return the value of the expression.  */
  3395. static int
  3396. evaluate_absolute (insn)
  3397.      struct pa_it *insn;
  3398. {
  3399.   int value;
  3400.   expressionS exp;
  3401.   int field_selector = insn->field_selector;
  3402.  
  3403.   exp = insn->exp;
  3404.   value = exp.X_add_number;
  3405.  
  3406.   switch (field_selector)
  3407.     {
  3408.     /* No change.  */
  3409.     case e_fsel:
  3410.       break;
  3411.  
  3412.     /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits.  */
  3413.     case e_lssel:
  3414.       if (value & 0x00000400)
  3415.     value += 0x800;
  3416.       value = (value & 0xfffff800) >> 11;
  3417.       break;
  3418.  
  3419.     /* Sign extend from bit 21.  */
  3420.     case e_rssel:
  3421.       if (value & 0x00000400)
  3422.     value |= 0xfffff800;
  3423.       else
  3424.     value &= 0x7ff;
  3425.       break;
  3426.  
  3427.     /* Arithmetic shift right 11 bits.  */
  3428.     case e_lsel:
  3429.       value = (value & 0xfffff800) >> 11;
  3430.       break;
  3431.  
  3432.     /* Set bits 0-20 to zero.  */
  3433.     case e_rsel:
  3434.       value = value & 0x7ff;
  3435.       break;
  3436.  
  3437.     /* Add 0x800 and arithmetic shift right 11 bits.  */
  3438.     case e_ldsel:
  3439.       value += 0x800;
  3440.       value = (value & 0xfffff800) >> 11;
  3441.       break;
  3442.  
  3443.     /* Set bitgs 0-21 to one.  */
  3444.     case e_rdsel:
  3445.       value |= 0xfffff800;
  3446.       break;
  3447.  
  3448. #define RSEL_ROUND(c)  (((c) + 0x1000) & ~0x1fff)
  3449.     case e_rrsel:
  3450.       value = (RSEL_ROUND (value) & 0x7ff) + (value - RSEL_ROUND (value));
  3451.       break;
  3452.  
  3453.     case e_lrsel:
  3454.       value = (RSEL_ROUND (value) >> 11) & 0x1fffff;
  3455.       break;
  3456. #undef RSEL_ROUND
  3457.  
  3458.     default:
  3459.       BAD_CASE (field_selector);
  3460.       break;
  3461.     }
  3462.   return value;
  3463. }
  3464.  
  3465. /* Given an argument location specification return the associated
  3466.    argument location number.  */
  3467.  
  3468. static unsigned int
  3469. pa_build_arg_reloc (type_name)
  3470.      char *type_name;
  3471. {
  3472.  
  3473.   if (strncasecmp (type_name, "no", 2) == 0)
  3474.     return 0;
  3475.   if (strncasecmp (type_name, "gr", 2) == 0)
  3476.     return 1;
  3477.   else if (strncasecmp (type_name, "fr", 2) == 0)
  3478.     return 2;
  3479.   else if (strncasecmp (type_name, "fu", 2) == 0)
  3480.     return 3;
  3481.   else
  3482.     as_bad ("Invalid argument location: %s\n", type_name);
  3483.  
  3484.   return 0;
  3485. }
  3486.  
  3487. /* Encode and return an argument relocation specification for
  3488.    the given register in the location specified by arg_reloc.  */
  3489.  
  3490. static unsigned int
  3491. pa_align_arg_reloc (reg, arg_reloc)
  3492.      unsigned int reg;
  3493.      unsigned int arg_reloc;
  3494. {
  3495.   unsigned int new_reloc;
  3496.  
  3497.   new_reloc = arg_reloc;
  3498.   switch (reg)
  3499.     {
  3500.     case 0:
  3501.       new_reloc <<= 8;
  3502.       break;
  3503.     case 1:
  3504.       new_reloc <<= 6;
  3505.       break;
  3506.     case 2:
  3507.       new_reloc <<= 4;
  3508.       break;
  3509.     case 3:
  3510.       new_reloc <<= 2;
  3511.       break;
  3512.     default:
  3513.       as_bad ("Invalid argument description: %d", reg);
  3514.     }
  3515.  
  3516.   return new_reloc;
  3517. }
  3518.  
  3519. /* Parse a PA nullification completer (,n).  Return nonzero if the
  3520.    completer was found; return zero if no completer was found.  */
  3521.  
  3522. static int
  3523. pa_parse_nullif (s)
  3524.      char **s;
  3525. {
  3526.   int nullif;
  3527.  
  3528.   nullif = 0;
  3529.   if (**s == ',')
  3530.     {
  3531.       *s = *s + 1;
  3532.       if (strncasecmp (*s, "n", 1) == 0)
  3533.     nullif = 1;
  3534.       else
  3535.     {
  3536.       as_bad ("Invalid Nullification: (%c)", **s);
  3537.       nullif = 0;
  3538.     }
  3539.       *s = *s + 1;
  3540.     }
  3541.  
  3542.   return nullif;
  3543. }
  3544.  
  3545. /* Parse a non-negated compare/subtract completer returning the
  3546.    number (for encoding in instrutions) of the given completer.
  3547.  
  3548.    ISBRANCH specifies whether or not this is parsing a condition
  3549.    completer for a branch (vs a nullification completer for a
  3550.    computational instruction.  */
  3551.  
  3552. static int
  3553. pa_parse_nonneg_cmpsub_cmpltr (s, isbranch)
  3554.      char **s;
  3555.      int isbranch;
  3556. {
  3557.   int cmpltr;
  3558.   char *name = *s + 1;
  3559.   char c;
  3560.   char *save_s = *s;
  3561.  
  3562.   cmpltr = 0;
  3563.   if (**s == ',')
  3564.     {
  3565.       *s += 1;
  3566.       while (**s != ',' && **s != ' ' && **s != '\t')
  3567.     *s += 1;
  3568.       c = **s;
  3569.       **s = 0x00;
  3570.       if (strcmp (name, "=") == 0)
  3571.     {
  3572.       cmpltr = 1;
  3573.     }
  3574.       else if (strcmp (name, "<") == 0)
  3575.     {
  3576.       cmpltr = 2;
  3577.     }
  3578.       else if (strcmp (name, "<=") == 0)
  3579.     {
  3580.       cmpltr = 3;
  3581.     }
  3582.       else if (strcmp (name, "<<") == 0)
  3583.     {
  3584.       cmpltr = 4;
  3585.     }
  3586.       else if (strcmp (name, "<<=") == 0)
  3587.     {
  3588.       cmpltr = 5;
  3589.     }
  3590.       else if (strcasecmp (name, "sv") == 0)
  3591.     {
  3592.       cmpltr = 6;
  3593.     }
  3594.       else if (strcasecmp (name, "od") == 0)
  3595.     {
  3596.       cmpltr = 7;
  3597.     }
  3598.       /* If we have something like addb,n then there is no condition
  3599.          completer.  */
  3600.       else if (strcasecmp (name, "n") == 0 && isbranch)
  3601.     {
  3602.       cmpltr = 0;
  3603.     }
  3604.       else
  3605.     {
  3606.       cmpltr = -1;
  3607.     }
  3608.       **s = c;
  3609.     }
  3610.  
  3611.   /* Reset pointers if this was really a ,n for a branch instruction.  */
  3612.   if (cmpltr == 0 && *name == 'n' && isbranch)
  3613.     *s = save_s;
  3614.  
  3615.   return cmpltr;
  3616. }
  3617.  
  3618. /* Parse a negated compare/subtract completer returning the
  3619.    number (for encoding in instrutions) of the given completer.
  3620.  
  3621.    ISBRANCH specifies whether or not this is parsing a condition
  3622.    completer for a branch (vs a nullification completer for a
  3623.    computational instruction.  */
  3624.  
  3625. static int
  3626. pa_parse_neg_cmpsub_cmpltr (s, isbranch)
  3627.      char **s;
  3628.      int isbranch;
  3629. {
  3630.   int cmpltr;
  3631.   char *name = *s + 1;
  3632.   char c;
  3633.   char *save_s = *s;
  3634.  
  3635.   cmpltr = 0;
  3636.   if (**s == ',')
  3637.     {
  3638.       *s += 1;
  3639.       while (**s != ',' && **s != ' ' && **s != '\t')
  3640.     *s += 1;
  3641.       c = **s;
  3642.       **s = 0x00;
  3643.       if (strcasecmp (name, "tr") == 0)
  3644.     {
  3645.       cmpltr = 0;
  3646.     }
  3647.       else if (strcmp (name, "<>") == 0)
  3648.     {
  3649.       cmpltr = 1;
  3650.     }
  3651.       else if (strcmp (name, ">=") == 0)
  3652.     {
  3653.       cmpltr = 2;
  3654.     }
  3655.       else if (strcmp (name, ">") == 0)
  3656.     {
  3657.       cmpltr = 3;
  3658.     }
  3659.       else if (strcmp (name, ">>=") == 0)
  3660.     {
  3661.       cmpltr = 4;
  3662.     }
  3663.       else if (strcmp (name, ">>") == 0)
  3664.     {
  3665.       cmpltr = 5;
  3666.     }
  3667.       else if (strcasecmp (name, "nsv") == 0)
  3668.     {
  3669.       cmpltr = 6;
  3670.     }
  3671.       else if (strcasecmp (name, "ev") == 0)
  3672.     {
  3673.       cmpltr = 7;
  3674.     }
  3675.       /* If we have something like addb,n then there is no condition
  3676.          completer.  */
  3677.       else if (strcasecmp (name, "n") == 0 && isbranch)
  3678.     {
  3679.       cmpltr = 0;
  3680.     }
  3681.       else
  3682.     {
  3683.       cmpltr = -1;
  3684.     }
  3685.       **s = c;
  3686.     }
  3687.  
  3688.   /* Reset pointers if this was really a ,n for a branch instruction.  */
  3689.   if (cmpltr == 0 && *name == 'n' && isbranch)
  3690.     *s = save_s;
  3691.  
  3692.   return cmpltr;
  3693. }
  3694.  
  3695. /* Parse a non-negated addition completer returning the number
  3696.    (for encoding in instrutions) of the given completer.
  3697.  
  3698.    ISBRANCH specifies whether or not this is parsing a condition
  3699.    completer for a branch (vs a nullification completer for a
  3700.    computational instruction.  */
  3701.  
  3702. static int
  3703. pa_parse_nonneg_add_cmpltr (s, isbranch)
  3704.      char **s;
  3705.      int isbranch;
  3706. {
  3707.   int cmpltr;
  3708.   char *name = *s + 1;
  3709.   char c;
  3710.   char *save_s = *s;
  3711.  
  3712.   cmpltr = 0;
  3713.   if (**s == ',')
  3714.     {
  3715.       *s += 1;
  3716.       while (**s != ',' && **s != ' ' && **s != '\t')
  3717.     *s += 1;
  3718.       c = **s;
  3719.       **s = 0x00;
  3720.       if (strcmp (name, "=") == 0)
  3721.     {
  3722.       cmpltr = 1;
  3723.     }
  3724.       else if (strcmp (name, "<") == 0)
  3725.     {
  3726.       cmpltr = 2;
  3727.     }
  3728.       else if (strcmp (name, "<=") == 0)
  3729.     {
  3730.       cmpltr = 3;
  3731.     }
  3732.       else if (strcasecmp (name, "nuv") == 0)
  3733.     {
  3734.       cmpltr = 4;
  3735.     }
  3736.       else if (strcasecmp (name, "znv") == 0)
  3737.     {
  3738.       cmpltr = 5;
  3739.     }
  3740.       else if (strcasecmp (name, "sv") == 0)
  3741.     {
  3742.       cmpltr = 6;
  3743.     }
  3744.       else if (strcasecmp (name, "od") == 0)
  3745.     {
  3746.       cmpltr = 7;
  3747.     }
  3748.       /* If we have something like addb,n then there is no condition
  3749.          completer.  */
  3750.       else if (strcasecmp (name, "n") == 0 && isbranch)
  3751.     {
  3752.       cmpltr = 0;
  3753.     }
  3754.       else
  3755.     {
  3756.       cmpltr = -1;
  3757.     }
  3758.       **s = c;
  3759.     }
  3760.  
  3761.   /* Reset pointers if this was really a ,n for a branch instruction.  */
  3762.   if (cmpltr == 0 && *name == 'n' && isbranch)
  3763.     *s = save_s;
  3764.  
  3765.   return cmpltr;
  3766. }
  3767.  
  3768. /* Parse a negated addition completer returning the number
  3769.    (for encoding in instrutions) of the given completer.
  3770.  
  3771.    ISBRANCH specifies whether or not this is parsing a condition
  3772.    completer for a branch (vs a nullification completer for a
  3773.    computational instruction.  */
  3774.  
  3775. static int
  3776. pa_parse_neg_add_cmpltr (s, isbranch)
  3777.      char **s;
  3778.      int isbranch;
  3779. {
  3780.   int cmpltr;
  3781.   char *name = *s + 1;
  3782.   char c;
  3783.   char *save_s = *s;
  3784.  
  3785.   cmpltr = 0;
  3786.   if (**s == ',')
  3787.     {
  3788.       *s += 1;
  3789.       while (**s != ',' && **s != ' ' && **s != '\t')
  3790.     *s += 1;
  3791.       c = **s;
  3792.       **s = 0x00;
  3793.       if (strcasecmp (name, "tr") == 0)
  3794.     {
  3795.       cmpltr = 0;
  3796.     }
  3797.       else if (strcmp (name, "<>") == 0)
  3798.     {
  3799.       cmpltr = 1;
  3800.     }
  3801.       else if (strcmp (name, ">=") == 0)
  3802.     {
  3803.       cmpltr = 2;
  3804.     }
  3805.       else if (strcmp (name, ">") == 0)
  3806.     {
  3807.       cmpltr = 3;
  3808.     }
  3809.       else if (strcasecmp (name, "uv") == 0)
  3810.     {
  3811.       cmpltr = 4;
  3812.     }
  3813.       else if (strcasecmp (name, "vnz") == 0)
  3814.     {
  3815.       cmpltr = 5;
  3816.     }
  3817.       else if (strcasecmp (name, "nsv") == 0)
  3818.     {
  3819.       cmpltr = 6;
  3820.     }
  3821.       else if (strcasecmp (name, "ev") == 0)
  3822.     {
  3823.       cmpltr = 7;
  3824.     }
  3825.       /* If we have something like addb,n then there is no condition
  3826.          completer.  */
  3827.       else if (strcasecmp (name, "n") == 0 && isbranch)
  3828.     {
  3829.       cmpltr = 0;
  3830.     }
  3831.       else
  3832.     {
  3833.       cmpltr = -1;
  3834.     }
  3835.       **s = c;
  3836.     }
  3837.  
  3838.   /* Reset pointers if this was really a ,n for a branch instruction.  */
  3839.   if (cmpltr == 0 && *name == 'n' && isbranch)
  3840.     *s = save_s;
  3841.  
  3842.   return cmpltr;
  3843. }
  3844.  
  3845. /* Handle a .BLOCK type pseudo-op.  */
  3846.  
  3847. static void
  3848. pa_block (z)
  3849.      int z;
  3850. {
  3851.   char *p;
  3852.   long int temp_fill;
  3853.   unsigned int temp_size;
  3854.   int i;
  3855.  
  3856.   temp_size = get_absolute_expression ();
  3857.  
  3858.   /* Always fill with zeros, that's what the HP assembler does.  */
  3859.   temp_fill = 0;
  3860.  
  3861.   p = frag_var (rs_fill, (int) temp_size, (int) temp_size,
  3862.         (relax_substateT) 0, (symbolS *) 0, 1, NULL);
  3863.   bzero (p, temp_size);
  3864.  
  3865.   /* Convert 2 bytes at a time.  */
  3866.  
  3867.   for (i = 0; i < temp_size; i += 2)
  3868.     {
  3869.       md_number_to_chars (p + i,
  3870.               (valueT) temp_fill,
  3871.               (int) ((temp_size - i) > 2 ? 2 : (temp_size - i)));
  3872.     }
  3873.  
  3874.   pa_undefine_label ();
  3875.   demand_empty_rest_of_line ();
  3876. }
  3877.  
  3878. /* Handle a .CALL pseudo-op.  This involves storing away information
  3879.    about where arguments are to be found so the linker can detect
  3880.    (and correct) argument location mismatches between caller and callee.  */
  3881.  
  3882. static void
  3883. pa_call (unused)
  3884.      int unused;
  3885. {
  3886.   pa_call_args (&last_call_desc);
  3887.   demand_empty_rest_of_line ();
  3888. }
  3889.  
  3890. /* Do the dirty work of building a call descriptor which describes
  3891.    where the caller placed arguments to a function call.  */
  3892.  
  3893. static void
  3894. pa_call_args (call_desc)
  3895.      struct call_desc *call_desc;
  3896. {
  3897.   char *name, c, *p;
  3898.   unsigned int temp, arg_reloc;
  3899.  
  3900.   while (!is_end_of_statement ())
  3901.     {
  3902.       name = input_line_pointer;
  3903.       c = get_symbol_end ();
  3904.       /* Process a source argument.  */
  3905.       if ((strncasecmp (name, "argw", 4) == 0))
  3906.     {
  3907.       temp = atoi (name + 4);
  3908.       p = input_line_pointer;
  3909.       *p = c;
  3910.       input_line_pointer++;
  3911.       name = input_line_pointer;
  3912.       c = get_symbol_end ();
  3913.       arg_reloc = pa_build_arg_reloc (name);
  3914.       call_desc->arg_reloc |= pa_align_arg_reloc (temp, arg_reloc);
  3915.     }
  3916.       /* Process a return value.  */
  3917.       else if ((strncasecmp (name, "rtnval", 6) == 0))
  3918.     {
  3919.       p = input_line_pointer;
  3920.       *p = c;
  3921.       input_line_pointer++;
  3922.       name = input_line_pointer;
  3923.       c = get_symbol_end ();
  3924.       arg_reloc = pa_build_arg_reloc (name);
  3925.       call_desc->arg_reloc |= (arg_reloc & 0x3);
  3926.     }
  3927.       else
  3928.     {
  3929.       as_bad ("Invalid .CALL argument: %s", name);
  3930.     }
  3931.       p = input_line_pointer;
  3932.       *p = c;
  3933.       if (!is_end_of_statement ())
  3934.     input_line_pointer++;
  3935.     }
  3936. }
  3937.  
  3938. /* Return TRUE if FRAG1 and FRAG2 are the same.  */
  3939.  
  3940. static int
  3941. is_same_frag (frag1, frag2)
  3942.      fragS *frag1;
  3943.      fragS *frag2;
  3944. {
  3945.  
  3946.   if (frag1 == NULL)
  3947.     return (FALSE);
  3948.   else if (frag2 == NULL)
  3949.     return (FALSE);
  3950.   else if (frag1 == frag2)
  3951.     return (TRUE);
  3952.   else if (frag2->fr_type == rs_fill && frag2->fr_fix == 0)
  3953.     return (is_same_frag (frag1, frag2->fr_next));
  3954.   else
  3955.     return (FALSE);
  3956. }
  3957.  
  3958. #ifdef OBJ_ELF
  3959. /* Build an entry in the UNWIND subspace from the given function
  3960.    attributes in CALL_INFO.  This is not needed for SOM as using
  3961.    R_ENTRY and R_EXIT relocations allow the linker to handle building
  3962.    of the unwind spaces.  */
  3963.  
  3964. static void
  3965. pa_build_unwind_subspace (call_info)
  3966.      struct call_info *call_info;
  3967. {
  3968.   char *unwind;
  3969.   asection *seg, *save_seg;
  3970.   subsegT subseg, save_subseg;
  3971.   int i;
  3972.   char c, *p;
  3973.  
  3974.   /* Get into the right seg/subseg.  This may involve creating
  3975.      the seg the first time through.  Make sure to have the
  3976.      old seg/subseg so that we can reset things when we are done.  */
  3977.   subseg = SUBSEG_UNWIND;
  3978.   seg = bfd_get_section_by_name (stdoutput, UNWIND_SECTION_NAME);
  3979.   if (seg == ASEC_NULL)
  3980.     {
  3981.       seg = bfd_make_section_old_way (stdoutput, UNWIND_SECTION_NAME);
  3982.       bfd_set_section_flags (stdoutput, seg,
  3983.                  SEC_READONLY | SEC_HAS_CONTENTS
  3984.                  | SEC_LOAD | SEC_RELOC);
  3985.     }
  3986.  
  3987.   save_seg = now_seg;
  3988.   save_subseg = now_subseg;
  3989.   subseg_set (seg, subseg);
  3990.  
  3991.  
  3992.   /* Get some space to hold relocation information for the unwind
  3993.      descriptor.  */
  3994.   p = frag_more (4);
  3995.  
  3996.   /* Relocation info. for start offset of the function.  */
  3997.   fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
  3998.         call_info->start_symbol, (offsetT) 0,
  3999.         (expressionS *) NULL, 0, R_PARISC_DIR32, e_fsel, 32, 0, NULL);
  4000.  
  4001.   p = frag_more (4);
  4002.  
  4003.   /* Relocation info. for end offset of the function.  */
  4004.   fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
  4005.         call_info->end_symbol, (offsetT) 0,
  4006.         (expressionS *) NULL, 0, R_PARISC_DIR32, e_fsel, 32, 0, NULL);
  4007.  
  4008.   /* Dump it. */
  4009.   unwind = (char *) &call_info->ci_unwind;
  4010.   for (i = 8; i < sizeof (struct unwind_table); i++)
  4011.     {
  4012.       c = *(unwind + i);
  4013.       {
  4014.     FRAG_APPEND_1_CHAR (c);
  4015.       }
  4016.     }
  4017.  
  4018.   /* Return back to the original segment/subsegment.  */
  4019.   subseg_set (save_seg, save_subseg);
  4020. }
  4021. #endif
  4022.  
  4023. /* Process a .CALLINFO pseudo-op.  This information is used later
  4024.    to build unwind descriptors and maybe one day to support
  4025.    .ENTER and .LEAVE.  */
  4026.  
  4027. static void
  4028. pa_callinfo (unused)
  4029.      int unused;
  4030. {
  4031.   char *name, c, *p;
  4032.   int temp;
  4033.  
  4034.   /* .CALLINFO must appear within a procedure definition.  */
  4035.   if (!within_procedure)
  4036.     as_bad (".callinfo is not within a procedure definition");
  4037.  
  4038.   /* Mark the fact that we found the .CALLINFO for the
  4039.      current procedure.  */
  4040.   callinfo_found = TRUE;
  4041.  
  4042.   /* Iterate over the .CALLINFO arguments.  */
  4043.   while (!is_end_of_statement ())
  4044.     {
  4045.       name = input_line_pointer;
  4046.       c = get_symbol_end ();
  4047.       /* Frame size specification.  */
  4048.       if ((strncasecmp (name, "frame", 5) == 0))
  4049.     {
  4050.       p = input_line_pointer;
  4051.       *p = c;
  4052.       input_line_pointer++;
  4053.       temp = get_absolute_expression ();
  4054.       if ((temp & 0x3) != 0)
  4055.         {
  4056.           as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp);
  4057.           temp = 0;
  4058.         }
  4059.  
  4060.       /* callinfo is in bytes and unwind_desc is in 8 byte units.  */
  4061.       last_call_info->ci_unwind.descriptor.frame_size = temp / 8;
  4062.  
  4063.     }
  4064.       /* Entry register (GR, GR and SR) specifications.  */
  4065.       else if ((strncasecmp (name, "entry_gr", 8) == 0))
  4066.     {
  4067.       p = input_line_pointer;
  4068.       *p = c;
  4069.       input_line_pointer++;
  4070.       temp = get_absolute_expression ();
  4071.       /* The HP assembler accepts 19 as the high bound for ENTRY_GR
  4072.          even though %r19 is caller saved.  I think this is a bug in
  4073.          the HP assembler, and we are not going to emulate it.  */
  4074.       if (temp < 3 || temp > 18)
  4075.         as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
  4076.       last_call_info->ci_unwind.descriptor.entry_gr = temp - 2;
  4077.     }
  4078.       else if ((strncasecmp (name, "entry_fr", 8) == 0))
  4079.     {
  4080.       p = input_line_pointer;
  4081.       *p = c;
  4082.       input_line_pointer++;
  4083.       temp = get_absolute_expression ();
  4084.       /* Similarly the HP assembler takes 31 as the high bound even
  4085.          though %fr21 is the last callee saved floating point register.  */
  4086.       if (temp < 12 || temp > 21)
  4087.         as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
  4088.       last_call_info->ci_unwind.descriptor.entry_fr = temp - 11;
  4089.     }
  4090.       else if ((strncasecmp (name, "entry_sr", 8) == 0))
  4091.     {
  4092.       p = input_line_pointer;
  4093.       *p = c;
  4094.       input_line_pointer++;
  4095.       temp = get_absolute_expression ();
  4096.       if (temp != 3)
  4097.         as_bad ("Value for ENTRY_SR must be 3\n");
  4098.     }
  4099.       /* Note whether or not this function performs any calls.  */
  4100.       else if ((strncasecmp (name, "calls", 5) == 0) ||
  4101.            (strncasecmp (name, "caller", 6) == 0))
  4102.     {
  4103.       p = input_line_pointer;
  4104.       *p = c;
  4105.     }
  4106.       else if ((strncasecmp (name, "no_calls", 8) == 0))
  4107.     {
  4108.       p = input_line_pointer;
  4109.       *p = c;
  4110.     }
  4111.       /* Should RP be saved into the stack.  */
  4112.       else if ((strncasecmp (name, "save_rp", 7) == 0))
  4113.     {
  4114.       p = input_line_pointer;
  4115.       *p = c;
  4116.       last_call_info->ci_unwind.descriptor.save_rp = 1;
  4117.     }
  4118.       /* Likewise for SP.  */
  4119.       else if ((strncasecmp (name, "save_sp", 7) == 0))
  4120.     {
  4121.       p = input_line_pointer;
  4122.       *p = c;
  4123.       last_call_info->ci_unwind.descriptor.save_sp = 1;
  4124.     }
  4125.       /* Is this an unwindable procedure.  If so mark it so
  4126.          in the unwind descriptor.  */
  4127.       else if ((strncasecmp (name, "no_unwind", 9) == 0))
  4128.     {
  4129.       p = input_line_pointer;
  4130.       *p = c;
  4131.       last_call_info->ci_unwind.descriptor.cannot_unwind = 1;
  4132.     }
  4133.       /* Is this an interrupt routine.  If so mark it in the
  4134.          unwind descriptor.  */
  4135.       else if ((strncasecmp (name, "hpux_int", 7) == 0))
  4136.     {
  4137.       p = input_line_pointer;
  4138.       *p = c;
  4139.       last_call_info->ci_unwind.descriptor.hpux_interrupt_marker = 1;
  4140.     }
  4141.       /* Is this a millicode routine.  "millicode" isn't in my
  4142.      assembler manual, but my copy is old.  The HP assembler
  4143.      accepts it, and there's a place in the unwind descriptor
  4144.      to drop the information, so we'll accept it too.  */
  4145.       else if ((strncasecmp (name, "millicode", 9) == 0))
  4146.     {
  4147.       p = input_line_pointer;
  4148.       *p = c;
  4149.       last_call_info->ci_unwind.descriptor.millicode = 1;
  4150.     }
  4151.       else
  4152.     {
  4153.       as_bad ("Invalid .CALLINFO argument: %s", name);
  4154.       *input_line_pointer = c;
  4155.     }
  4156.       if (!is_end_of_statement ())
  4157.     input_line_pointer++;
  4158.     }
  4159.  
  4160.   demand_empty_rest_of_line ();
  4161. }
  4162.  
  4163. /* Switch into the code subspace.  */
  4164.  
  4165. static void
  4166. pa_code (unused)
  4167.      int unused;
  4168. {
  4169.   sd_chain_struct *sdchain;
  4170.  
  4171.   /* First time through it might be necessary to create the
  4172.      $TEXT$ space.  */
  4173.   if ((sdchain = is_defined_space ("$TEXT$")) == NULL)
  4174.     {
  4175.       sdchain = create_new_space (pa_def_spaces[0].name,
  4176.                   pa_def_spaces[0].spnum,
  4177.                   pa_def_spaces[0].loadable,
  4178.                   pa_def_spaces[0].defined,
  4179.                   pa_def_spaces[0].private,
  4180.                   pa_def_spaces[0].sort,
  4181.                   pa_def_spaces[0].segment, 0);
  4182.     }
  4183.  
  4184.   SPACE_DEFINED (sdchain) = 1;
  4185.   subseg_set (text_section, SUBSEG_CODE);
  4186.   demand_empty_rest_of_line ();
  4187. }
  4188.  
  4189. /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
  4190.    the .comm pseudo-op has the following symtax:
  4191.  
  4192.    <label> .comm <length>
  4193.  
  4194.    where <label> is optional and is a symbol whose address will be the start of
  4195.    a block of memory <length> bytes long. <length> must be an absolute
  4196.    expression.  <length> bytes will be allocated in the current space
  4197.    and subspace.  */
  4198.  
  4199. static void
  4200. pa_comm (unused)
  4201.      int unused;
  4202. {
  4203.   unsigned int size;
  4204.   symbolS *symbol;
  4205.   label_symbol_struct *label_symbol = pa_get_label ();
  4206.  
  4207.   if (label_symbol)
  4208.     symbol = label_symbol->lss_label;
  4209.   else
  4210.     symbol = NULL;
  4211.  
  4212.   SKIP_WHITESPACE ();
  4213.   size = get_absolute_expression ();
  4214.  
  4215.   if (symbol)
  4216.     {
  4217.       /* It is incorrect to check S_IS_DEFINED at this point as
  4218.          the symbol will *always* be defined.  FIXME.  How to
  4219.          correctly determine when this label really as been
  4220.          defined before.  */
  4221.       if (S_GET_VALUE (symbol))
  4222.     {
  4223.       if (S_GET_VALUE (symbol) != size)
  4224.         {
  4225.           as_warn ("Length of .comm \"%s\" is already %ld. Not changed.",
  4226.                S_GET_NAME (symbol), S_GET_VALUE (symbol));
  4227.           return;
  4228.         }
  4229.     }
  4230.       else
  4231.     {
  4232.       S_SET_VALUE (symbol, size);
  4233.       S_SET_SEGMENT (symbol, bfd_und_section_ptr);
  4234.       S_SET_EXTERNAL (symbol);
  4235.  
  4236.       /* colon() has already set the frag to the current location in the
  4237.          $BSS$ subspace; we need to reset the fragment to the zero address
  4238.          fragment.  */
  4239.       symbol->sy_frag = &zero_address_frag;
  4240.     }
  4241.     }
  4242.   demand_empty_rest_of_line ();
  4243. }
  4244.  
  4245. /* Process a .END pseudo-op.  */
  4246.  
  4247. static void
  4248. pa_end (unused)
  4249.      int unused;
  4250. {
  4251.   demand_empty_rest_of_line ();
  4252. }
  4253.  
  4254. /* Process a .ENTER pseudo-op.  This is not supported.  */
  4255. static void
  4256. pa_enter (unused)
  4257.      int unused;
  4258. {
  4259.   abort ();
  4260. }
  4261.  
  4262. /* Process a .ENTRY pseudo-op.  .ENTRY marks the beginning of the
  4263.    procesure.  */
  4264. static void
  4265. pa_entry (unused)
  4266.      int unused;
  4267. {
  4268.   if (!within_procedure)
  4269.     as_bad ("Misplaced .entry. Ignored.");
  4270.   else
  4271.     {
  4272.       if (!callinfo_found)
  4273.     as_bad ("Missing .callinfo.");
  4274.     }
  4275.   demand_empty_rest_of_line ();
  4276.   within_entry_exit = TRUE;
  4277.  
  4278. #ifdef OBJ_SOM
  4279.   /* SOM defers building of unwind descriptors until the link phase.
  4280.      The assembler is responsible for creating an R_ENTRY relocation
  4281.      to mark the beginning of a region and hold the unwind bits, and
  4282.      for creating an R_EXIT relocation to mark the end of the region.
  4283.  
  4284.      FIXME.  ELF should be using the same conventions!  The problem
  4285.      is an unwind requires too much relocation space.  Hmmm.  Maybe
  4286.      if we split the unwind bits up between the relocations which
  4287.      denote the entry and exit points.  */
  4288.   if (last_call_info->start_symbol != NULL)
  4289.     {
  4290.       char *where = frag_more (0);
  4291.  
  4292.       fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  4293.             NULL, (offsetT) 0, NULL,
  4294.             0, R_HPPA_ENTRY, e_fsel, 0, 0,
  4295.             (int *) &last_call_info->ci_unwind.descriptor);
  4296.     }
  4297. #endif
  4298. }
  4299.  
  4300. /* Handle a .EQU pseudo-op.  */
  4301.  
  4302. static void
  4303. pa_equ (reg)
  4304.      int reg;
  4305. {
  4306.   label_symbol_struct *label_symbol = pa_get_label ();
  4307.   symbolS *symbol;
  4308.  
  4309.   if (label_symbol)
  4310.     {
  4311.       symbol = label_symbol->lss_label;
  4312.       if (reg)
  4313.     S_SET_VALUE (symbol, pa_parse_number (&input_line_pointer, 0));
  4314.       else
  4315.     S_SET_VALUE (symbol, (unsigned int) get_absolute_expression ());
  4316.       S_SET_SEGMENT (symbol, bfd_abs_section_ptr);
  4317.     }
  4318.   else
  4319.     {
  4320.       if (reg)
  4321.     as_bad (".REG must use a label");
  4322.       else
  4323.     as_bad (".EQU must use a label");
  4324.     }
  4325.  
  4326.   pa_undefine_label ();
  4327.   demand_empty_rest_of_line ();
  4328. }
  4329.  
  4330. /* Helper function.  Does processing for the end of a function.  This
  4331.    usually involves creating some relocations or building special
  4332.    symbols to mark the end of the function.  */
  4333.  
  4334. static void
  4335. process_exit ()
  4336. {
  4337.   char *where;
  4338.  
  4339.   where = frag_more (0);
  4340.  
  4341. #ifdef OBJ_ELF
  4342.   /* Mark the end of the function, stuff away the location of the frag
  4343.      for the end of the function, and finally call pa_build_unwind_subspace
  4344.      to add an entry in the unwind table.  */
  4345.   hppa_elf_mark_end_of_function ();
  4346.   pa_build_unwind_subspace (last_call_info);
  4347. #else
  4348.   /* SOM defers building of unwind descriptors until the link phase.
  4349.      The assembler is responsible for creating an R_ENTRY relocation
  4350.      to mark the beginning of a region and hold the unwind bits, and
  4351.      for creating an R_EXIT relocation to mark the end of the region.
  4352.  
  4353.      FIXME.  ELF should be using the same conventions!  The problem
  4354.      is an unwind requires too much relocation space.  Hmmm.  Maybe
  4355.      if we split the unwind bits up between the relocations which
  4356.      denote the entry and exit points.  */
  4357.   fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  4358.         NULL, (offsetT) 0,
  4359.         NULL, 0, R_HPPA_EXIT, e_fsel, 0, 0,
  4360.         (int *) &last_call_info->ci_unwind.descriptor + 1);
  4361. #endif
  4362. }
  4363.  
  4364. /* Process a .EXIT pseudo-op.  */
  4365.  
  4366. static void
  4367. pa_exit (unused)
  4368.      int unused;
  4369. {
  4370.   if (!within_procedure)
  4371.     as_bad (".EXIT must appear within a procedure");
  4372.   else
  4373.     {
  4374.       if (!callinfo_found)
  4375.     as_bad ("Missing .callinfo");
  4376.       else
  4377.     {
  4378.       if (!within_entry_exit)
  4379.         as_bad ("No .ENTRY for this .EXIT");
  4380.       else
  4381.         {
  4382.           within_entry_exit = FALSE;
  4383.           process_exit ();
  4384.         }
  4385.     }
  4386.     }
  4387.   demand_empty_rest_of_line ();
  4388. }
  4389.  
  4390. /* Process a .EXPORT directive.  This makes functions external
  4391.    and provides information such as argument relocation entries
  4392.    to callers.  */
  4393.  
  4394. static void
  4395. pa_export (unused)
  4396.      int unused;
  4397. {
  4398.   char *name, c, *p;
  4399.   symbolS *symbol;
  4400.  
  4401.   name = input_line_pointer;
  4402.   c = get_symbol_end ();
  4403.   /* Make sure the given symbol exists.  */
  4404.   if ((symbol = symbol_find_or_make (name)) == NULL)
  4405.     {
  4406.       as_bad ("Cannot define export symbol: %s\n", name);
  4407.       p = input_line_pointer;
  4408.       *p = c;
  4409.       input_line_pointer++;
  4410.     }
  4411.   else
  4412.     {
  4413.       /* OK.  Set the external bits and process argument relocations.  */
  4414.       S_SET_EXTERNAL (symbol);
  4415.       p = input_line_pointer;
  4416.       *p = c;
  4417.       if (!is_end_of_statement ())
  4418.     {
  4419.       input_line_pointer++;
  4420.       pa_type_args (symbol, 1);
  4421.     }
  4422.     }
  4423.  
  4424.   demand_empty_rest_of_line ();
  4425. }
  4426.  
  4427. /* Helper function to process arguments to a .EXPORT pseudo-op.  */
  4428.  
  4429. static void
  4430. pa_type_args (symbolP, is_export)
  4431.      symbolS *symbolP;
  4432.      int is_export;
  4433. {
  4434.   char *name, c, *p;
  4435.   unsigned int temp, arg_reloc;
  4436.   pa_symbol_type type = SYMBOL_TYPE_UNKNOWN;
  4437.   obj_symbol_type *symbol = (obj_symbol_type *) symbolP->bsym;
  4438.  
  4439.   if (strncasecmp (input_line_pointer, "absolute", 8) == 0)
  4440.  
  4441.     {
  4442.       input_line_pointer += 8;
  4443.       symbolP->bsym->flags &= ~BSF_FUNCTION;
  4444.       S_SET_SEGMENT (symbolP, bfd_abs_section_ptr);
  4445.       type = SYMBOL_TYPE_ABSOLUTE;
  4446.     }
  4447.   else if (strncasecmp (input_line_pointer, "code", 4) == 0)
  4448.     {
  4449.       input_line_pointer += 4;
  4450.       /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
  4451.          instead one should be IMPORTing/EXPORTing ENTRY types.
  4452.  
  4453.          Complain if one tries to EXPORT a CODE type since that's never
  4454.          done.  Both GCC and HP C still try to IMPORT CODE types, so
  4455.          silently fix them to be ENTRY types.  */
  4456.       if (symbolP->bsym->flags & BSF_FUNCTION)
  4457.     {
  4458.       if (is_export)
  4459.         as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP->bsym->name);
  4460.  
  4461.       symbolP->bsym->flags |= BSF_FUNCTION;
  4462.       type = SYMBOL_TYPE_ENTRY;
  4463.     }
  4464.       else
  4465.     {
  4466.       symbolP->bsym->flags &= ~BSF_FUNCTION;
  4467.       type = SYMBOL_TYPE_CODE;
  4468.     }
  4469.     }
  4470.   else if (strncasecmp (input_line_pointer, "data", 4) == 0)
  4471.     {
  4472.       input_line_pointer += 4;
  4473.       symbolP->bsym->flags &= ~BSF_FUNCTION;
  4474.       type = SYMBOL_TYPE_DATA;
  4475.     }
  4476.   else if ((strncasecmp (input_line_pointer, "entry", 5) == 0))
  4477.     {
  4478.       input_line_pointer += 5;
  4479.       symbolP->bsym->flags |= BSF_FUNCTION;
  4480.       type = SYMBOL_TYPE_ENTRY;
  4481.     }
  4482.   else if (strncasecmp (input_line_pointer, "millicode", 9) == 0)
  4483.     {
  4484.       input_line_pointer += 9;
  4485.       symbolP->bsym->flags |= BSF_FUNCTION;
  4486.       type = SYMBOL_TYPE_MILLICODE;
  4487.     }
  4488.   else if (strncasecmp (input_line_pointer, "plabel", 6) == 0)
  4489.     {
  4490.       input_line_pointer += 6;
  4491.       symbolP->bsym->flags &= ~BSF_FUNCTION;
  4492.       type = SYMBOL_TYPE_PLABEL;
  4493.     }
  4494.   else if (strncasecmp (input_line_pointer, "pri_prog", 8) == 0)
  4495.     {
  4496.       input_line_pointer += 8;
  4497.       symbolP->bsym->flags |= BSF_FUNCTION;
  4498.       type = SYMBOL_TYPE_PRI_PROG;
  4499.     }
  4500.   else if (strncasecmp (input_line_pointer, "sec_prog", 8) == 0)
  4501.     {
  4502.       input_line_pointer += 8;
  4503.       symbolP->bsym->flags |= BSF_FUNCTION;
  4504.       type = SYMBOL_TYPE_SEC_PROG;
  4505.     }
  4506.  
  4507.   /* SOM requires much more information about symbol types
  4508.      than BFD understands.  This is how we get this information
  4509.      to the SOM BFD backend.  */
  4510. #ifdef obj_set_symbol_type
  4511.   obj_set_symbol_type (symbolP->bsym, (int) type);
  4512. #endif
  4513.  
  4514.   /* Now that the type of the exported symbol has been handled,
  4515.      handle any argument relocation information.  */
  4516.   while (!is_end_of_statement ())
  4517.     {
  4518.       if (*input_line_pointer == ',')
  4519.     input_line_pointer++;
  4520.       name = input_line_pointer;
  4521.       c = get_symbol_end ();
  4522.       /* Argument sources.  */
  4523.       if ((strncasecmp (name, "argw", 4) == 0))
  4524.     {
  4525.       p = input_line_pointer;
  4526.       *p = c;
  4527.       input_line_pointer++;
  4528.       temp = atoi (name + 4);
  4529.       name = input_line_pointer;
  4530.       c = get_symbol_end ();
  4531.       arg_reloc = pa_align_arg_reloc (temp, pa_build_arg_reloc (name));
  4532.       symbol->tc_data.hppa_arg_reloc |= arg_reloc;
  4533.       *input_line_pointer = c;
  4534.     }
  4535.       /* The return value.  */
  4536.       else if ((strncasecmp (name, "rtnval", 6)) == 0)
  4537.     {
  4538.       p = input_line_pointer;
  4539.       *p = c;
  4540.       input_line_pointer++;
  4541.       name = input_line_pointer;
  4542.       c = get_symbol_end ();
  4543.       arg_reloc = pa_build_arg_reloc (name);
  4544.       symbol->tc_data.hppa_arg_reloc |= arg_reloc;
  4545.       *input_line_pointer = c;
  4546.     }
  4547.       /* Privelege level.  */
  4548.       else if ((strncasecmp (name, "priv_lev", 8)) == 0)
  4549.     {
  4550.       p = input_line_pointer;
  4551.       *p = c;
  4552.       input_line_pointer++;
  4553.       temp = atoi (input_line_pointer);
  4554.       c = get_symbol_end ();
  4555.       *input_line_pointer = c;
  4556.     }
  4557.       else
  4558.     {
  4559.       as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name);
  4560.       p = input_line_pointer;
  4561.       *p = c;
  4562.     }
  4563.       if (!is_end_of_statement ())
  4564.     input_line_pointer++;
  4565.     }
  4566. }
  4567.  
  4568. /* Handle an .IMPORT pseudo-op.  Any symbol referenced in a given
  4569.    assembly file must either be defined in the assembly file, or
  4570.    explicitly IMPORTED from another.  */
  4571.  
  4572. static void
  4573. pa_import (unused)
  4574.      int unused;
  4575. {
  4576.   char *name, c, *p;
  4577.   symbolS *symbol;
  4578.  
  4579.   name = input_line_pointer;
  4580.   c = get_symbol_end ();
  4581.  
  4582.   symbol = symbol_find (name);
  4583.   /* Ugh.  We might be importing a symbol defined earlier in the file,
  4584.      in which case all the code below will really screw things up
  4585.      (set the wrong segment, symbol flags & type, etc).  */
  4586.   if (symbol == NULL || !S_IS_DEFINED (symbol))
  4587.     {
  4588.       symbol = symbol_find_or_make (name);
  4589.       p = input_line_pointer;
  4590.       *p = c;
  4591.  
  4592.       if (!is_end_of_statement ())
  4593.     {
  4594.       input_line_pointer++;
  4595.       pa_type_args (symbol, 0);
  4596.     }
  4597.       else
  4598.     {
  4599.       /* Sigh.  To be compatable with the HP assembler and to help
  4600.          poorly written assembly code, we assign a type based on
  4601.          the the current segment.  Note only BSF_FUNCTION really
  4602.          matters, we do not need to set the full SYMBOL_TYPE_* info.  */
  4603.       if (now_seg == text_section)
  4604.         symbol->bsym->flags |= BSF_FUNCTION;
  4605.  
  4606.       /* If the section is undefined, then the symbol is undefined
  4607.          Since this is an import, leave the section undefined.  */
  4608.       S_SET_SEGMENT (symbol, bfd_und_section_ptr);
  4609.     }
  4610.     }
  4611.   else
  4612.     {
  4613.       /* The symbol was already defined.  Just eat everything up to
  4614.      the end of the current statement.  */
  4615.       while (!is_end_of_statement ())
  4616.     input_line_pointer++;
  4617.     }
  4618.  
  4619.   demand_empty_rest_of_line ();
  4620. }
  4621.  
  4622. /* Handle a .LABEL pseudo-op.  */
  4623.  
  4624. static void
  4625. pa_label (unused)
  4626.      int unused;
  4627. {
  4628.   char *name, c, *p;
  4629.  
  4630.   name = input_line_pointer;
  4631.   c = get_symbol_end ();
  4632.  
  4633.   if (strlen (name) > 0)
  4634.     {
  4635.       colon (name);
  4636.       p = input_line_pointer;
  4637.       *p = c;
  4638.     }
  4639.   else
  4640.     {
  4641.       as_warn ("Missing label name on .LABEL");
  4642.     }
  4643.  
  4644.   if (!is_end_of_statement ())
  4645.     {
  4646.       as_warn ("extra .LABEL arguments ignored.");
  4647.       ignore_rest_of_line ();
  4648.     }
  4649.   demand_empty_rest_of_line ();
  4650. }
  4651.  
  4652. /* Handle a .LEAVE pseudo-op.  This is not supported yet.  */
  4653.  
  4654. static void
  4655. pa_leave (unused)
  4656.      int unused;
  4657. {
  4658.   abort ();
  4659. }
  4660.  
  4661. /* Handle a .ORIGIN pseudo-op.  */
  4662.  
  4663. static void
  4664. pa_origin (unused)
  4665.      int unused;
  4666. {
  4667.   s_org (0);
  4668.   pa_undefine_label ();
  4669. }
  4670.  
  4671. /* Handle a .PARAM pseudo-op.  This is much like a .EXPORT, except it
  4672.    is for static functions.  FIXME.  Should share more code with .EXPORT.  */
  4673.  
  4674. static void
  4675. pa_param (unused)
  4676.      int unused;
  4677. {
  4678.   char *name, c, *p;
  4679.   symbolS *symbol;
  4680.  
  4681.   name = input_line_pointer;
  4682.   c = get_symbol_end ();
  4683.  
  4684.   if ((symbol = symbol_find_or_make (name)) == NULL)
  4685.     {
  4686.       as_bad ("Cannot define static symbol: %s\n", name);
  4687.       p = input_line_pointer;
  4688.       *p = c;
  4689.       input_line_pointer++;
  4690.     }
  4691.   else
  4692.     {
  4693.       S_CLEAR_EXTERNAL (symbol);
  4694.       p = input_line_pointer;
  4695.       *p = c;
  4696.       if (!is_end_of_statement ())
  4697.     {
  4698.       input_line_pointer++;
  4699.       pa_type_args (symbol, 0);
  4700.     }
  4701.     }
  4702.  
  4703.   demand_empty_rest_of_line ();
  4704. }
  4705.  
  4706. /* Handle a .PROC pseudo-op.  It is used to mark the beginning
  4707.    of a procedure from a syntatical point of view.  */
  4708.  
  4709. static void
  4710. pa_proc (unused)
  4711.      int unused;
  4712. {
  4713.   struct call_info *call_info;
  4714.   if (within_procedure)
  4715.     as_fatal ("Nested procedures");
  4716.  
  4717.   /* Reset global variables for new procedure.  */
  4718.   callinfo_found = FALSE;
  4719.   within_procedure = TRUE;
  4720.  
  4721. #if 0
  4722.   Enabling this code creates severe problems with GDB.  It appears as if
  4723.   inserting linker stubs between functions within a single .o makes GDB
  4724.   blow chunks.
  4725.  
  4726.   /* Create a new CODE subspace for each procedure if we are not
  4727.      using space/subspace aliases.  */
  4728.   if (!USE_ALIASES && call_info_root != NULL)
  4729.     {
  4730.       segT seg;
  4731.  
  4732.       /* Force creation of a new $CODE$ subspace; inherit attributes from
  4733.      the first $CODE$ subspace.  */
  4734.       seg = subseg_force_new ("$CODE$", 0);
  4735.  
  4736.       /* Now set the flags.  */
  4737.       bfd_set_section_flags (stdoutput, seg,
  4738.                  bfd_get_section_flags (abfd, text_section));
  4739.  
  4740.       /* Record any alignment request for this section.  */
  4741.       record_alignment (seg,
  4742.             bfd_get_section_alignment (stdoutput, text_section));
  4743.  
  4744.       /* Change the "text_section" to be our new $CODE$ subspace.  */
  4745.       text_section = seg;
  4746.       subseg_set (text_section, 0);
  4747.  
  4748. #ifdef obj_set_subsection_attributes
  4749.       /* Need a way to inherit the the access bits, sort key and quadrant
  4750.      from the first $CODE$ subspace.  FIXME.  */
  4751.       obj_set_subsection_attributes (seg, current_space->sd_seg, 0x2c, 24, 0);
  4752. #endif
  4753.     }
  4754. #endif
  4755.  
  4756.   /* Create another call_info structure.  */
  4757.   call_info = (struct call_info *) xmalloc (sizeof (struct call_info));
  4758.  
  4759.   if (!call_info)
  4760.     as_fatal ("Cannot allocate unwind descriptor\n");
  4761.  
  4762.   bzero (call_info, sizeof (struct call_info));
  4763.  
  4764.   call_info->ci_next = NULL;
  4765.  
  4766.   if (call_info_root == NULL)
  4767.     {
  4768.       call_info_root = call_info;
  4769.       last_call_info = call_info;
  4770.     }
  4771.   else
  4772.     {
  4773.       last_call_info->ci_next = call_info;
  4774.       last_call_info = call_info;
  4775.     }
  4776.  
  4777.   /* set up defaults on call_info structure */
  4778.  
  4779.   call_info->ci_unwind.descriptor.cannot_unwind = 0;
  4780.   call_info->ci_unwind.descriptor.region_desc = 1;
  4781.   call_info->ci_unwind.descriptor.hpux_interrupt_marker = 0;
  4782.  
  4783.   /* If we got a .PROC pseudo-op, we know that the function is defined
  4784.      locally.  Make sure it gets into the symbol table.  */
  4785.   {
  4786.     label_symbol_struct *label_symbol = pa_get_label ();
  4787.  
  4788.     if (label_symbol)
  4789.       {
  4790.     if (label_symbol->lss_label)
  4791.       {
  4792.         last_call_info->start_symbol = label_symbol->lss_label;
  4793.         label_symbol->lss_label->bsym->flags |= BSF_FUNCTION;
  4794. #if 0
  4795.         if (! USE_ALIASES)
  4796.           {
  4797.         /* The label was defined in a different segment.  Fix that
  4798.            along with the value and associated fragment.  */
  4799.         S_SET_SEGMENT (last_call_info->start_symbol, now_seg);
  4800.                 S_SET_VALUE (last_call_info->start_symbol,
  4801.                  ((char*)obstack_next_free (&frags)
  4802.                    - frag_now->fr_literal));
  4803.         last_call_info->start_symbol->sy_frag = frag_now;
  4804.           }
  4805. #endif
  4806.       }
  4807.     else
  4808.       as_bad ("Missing function name for .PROC (corrupted label chain)");
  4809.       }
  4810.     else
  4811.       last_call_info->start_symbol = NULL;
  4812.   }
  4813.  
  4814.   demand_empty_rest_of_line ();
  4815. }
  4816.  
  4817. /* Process the syntatical end of a procedure.  Make sure all the
  4818.    appropriate pseudo-ops were found within the procedure.  */
  4819.  
  4820. static void
  4821. pa_procend (unused)
  4822.      int unused;
  4823. {
  4824.  
  4825.   /* If we are within a procedure definition, make sure we've
  4826.      defined a label for the procedure; handle case where the
  4827.      label was defined after the .PROC directive.
  4828.  
  4829.      Note there's not need to diddle with the segment or fragment
  4830.      for the label symbol in this case.  We have already switched
  4831.      into the new $CODE$ subspace at this point.  */
  4832.   if (within_procedure && last_call_info->start_symbol == NULL)
  4833.     {
  4834.       label_symbol_struct *label_symbol = pa_get_label ();
  4835.  
  4836.       if (label_symbol)
  4837.     {
  4838.       if (label_symbol->lss_label)
  4839.         {
  4840.           last_call_info->start_symbol = label_symbol->lss_label;
  4841.           label_symbol->lss_label->bsym->flags |= BSF_FUNCTION;
  4842. #ifdef OBJ_SOM
  4843.           /* Also handle allocation of a fixup to hold the unwind
  4844.          information when the label appears after the proc/procend.  */
  4845.           if (within_entry_exit)
  4846.         {
  4847.           char *where = frag_more (0);
  4848.  
  4849.           fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  4850.                 NULL, (offsetT) 0, NULL,
  4851.                 0, R_HPPA_ENTRY, e_fsel, 0, 0,
  4852.                 (int *) &last_call_info->ci_unwind.descriptor);
  4853.         }
  4854. #endif
  4855.         }
  4856.       else
  4857.         as_bad ("Missing function name for .PROC (corrupted label chain)");
  4858.     }
  4859.       else
  4860.     as_bad ("Missing function name for .PROC");
  4861.     }
  4862.  
  4863.   if (!within_procedure)
  4864.     as_bad ("misplaced .procend");
  4865.  
  4866.   if (!callinfo_found)
  4867.     as_bad ("Missing .callinfo for this procedure");
  4868.  
  4869.   if (within_entry_exit)
  4870.     as_bad ("Missing .EXIT for a .ENTRY");
  4871.  
  4872. #ifdef OBJ_ELF
  4873.   /* ELF needs to mark the end of each function so that it can compute
  4874.      the size of the function (apparently its needed in the symbol table.  */
  4875.   hppa_elf_mark_end_of_function ();
  4876. #endif
  4877.  
  4878.   within_procedure = FALSE;
  4879.   demand_empty_rest_of_line ();
  4880.   pa_undefine_label ();
  4881. }
  4882.  
  4883. /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
  4884.    then create a new space entry to hold the information specified
  4885.    by the parameters to the .SPACE directive.  */
  4886.  
  4887. static sd_chain_struct *
  4888. pa_parse_space_stmt (space_name, create_flag)
  4889.      char *space_name;
  4890.      int create_flag;
  4891. {
  4892.   char *name, *ptemp, c;
  4893.   char loadable, defined, private, sort;
  4894.   int spnum, temp;
  4895.   asection *seg = NULL;
  4896.   sd_chain_struct *space;
  4897.  
  4898.   /* load default values */
  4899.   spnum = 0;
  4900.   sort = 0;
  4901.   loadable = TRUE;
  4902.   defined = TRUE;
  4903.   private = FALSE;
  4904.   if (strcmp (space_name, "$TEXT$") == 0)
  4905.     {
  4906.       seg = pa_def_spaces[0].segment;
  4907.       defined = pa_def_spaces[0].defined;
  4908.       private = pa_def_spaces[0].private;
  4909.       sort = pa_def_spaces[0].sort;
  4910.       spnum = pa_def_spaces[0].spnum;
  4911.     }
  4912.   else if (strcmp (space_name, "$PRIVATE$") == 0)
  4913.     {
  4914.       seg = pa_def_spaces[1].segment;
  4915.       defined = pa_def_spaces[1].defined;
  4916.       private = pa_def_spaces[1].private;
  4917.       sort = pa_def_spaces[1].sort;
  4918.       spnum = pa_def_spaces[1].spnum;
  4919.     }
  4920.  
  4921.   if (!is_end_of_statement ())
  4922.     {
  4923.       print_errors = FALSE;
  4924.       ptemp = input_line_pointer + 1;
  4925.       /* First see if the space was specified as a number rather than
  4926.          as a name.  According to the PA assembly manual the rest of
  4927.          the line should be ignored.  */
  4928.       temp = pa_parse_number (&ptemp, 0);
  4929.       if (temp >= 0)
  4930.     {
  4931.       spnum = temp;
  4932.       input_line_pointer = ptemp;
  4933.     }
  4934.       else
  4935.     {
  4936.       while (!is_end_of_statement ())
  4937.         {
  4938.           input_line_pointer++;
  4939.           name = input_line_pointer;
  4940.           c = get_symbol_end ();
  4941.           if ((strncasecmp (name, "spnum", 5) == 0))
  4942.         {
  4943.           *input_line_pointer = c;
  4944.           input_line_pointer++;
  4945.           spnum = get_absolute_expression ();
  4946.         }
  4947.           else if ((strncasecmp (name, "sort", 4) == 0))
  4948.         {
  4949.           *input_line_pointer = c;
  4950.           input_line_pointer++;
  4951.           sort = get_absolute_expression ();
  4952.         }
  4953.           else if ((strncasecmp (name, "unloadable", 10) == 0))
  4954.         {
  4955.           *input_line_pointer = c;
  4956.           loadable = FALSE;
  4957.         }
  4958.           else if ((strncasecmp (name, "notdefined", 10) == 0))
  4959.         {
  4960.           *input_line_pointer = c;
  4961.           defined = FALSE;
  4962.         }
  4963.           else if ((strncasecmp (name, "private", 7) == 0))
  4964.         {
  4965.           *input_line_pointer = c;
  4966.           private = TRUE;
  4967.         }
  4968.           else
  4969.         {
  4970.           as_bad ("Invalid .SPACE argument");
  4971.           *input_line_pointer = c;
  4972.           if (!is_end_of_statement ())
  4973.             input_line_pointer++;
  4974.         }
  4975.         }
  4976.     }
  4977.       print_errors = TRUE;
  4978.     }
  4979.  
  4980.   if (create_flag && seg == NULL)
  4981.     seg = subseg_new (space_name, 0);
  4982.  
  4983.   /* If create_flag is nonzero, then create the new space with
  4984.      the attributes computed above.  Else set the values in
  4985.      an already existing space -- this can only happen for
  4986.      the first occurence of a built-in space.  */
  4987.   if (create_flag)
  4988.     space = create_new_space (space_name, spnum, loadable, defined,
  4989.                   private, sort, seg, 1);
  4990.   else
  4991.     {
  4992.       space = is_defined_space (space_name);
  4993.       SPACE_SPNUM (space) = spnum;
  4994.       SPACE_DEFINED (space) = defined & 1;
  4995.       SPACE_USER_DEFINED (space) = 1;
  4996.     }
  4997.  
  4998. #ifdef obj_set_section_attributes
  4999.   obj_set_section_attributes (seg, defined, private, sort, spnum);
  5000. #endif
  5001.  
  5002.   return space;
  5003. }
  5004.  
  5005. /* Handle a .SPACE pseudo-op; this switches the current space to the
  5006.    given space, creating the new space if necessary.  */
  5007.  
  5008. static void
  5009. pa_space (unused)
  5010.      int unused;
  5011. {
  5012.   char *name, c, *space_name, *save_s;
  5013.   int temp;
  5014.   sd_chain_struct *sd_chain;
  5015.  
  5016.   if (within_procedure)
  5017.     {
  5018.       as_bad ("Can\'t change spaces within a procedure definition. Ignored");
  5019.       ignore_rest_of_line ();
  5020.     }
  5021.   else
  5022.     {
  5023.       /* Check for some of the predefined spaces.   FIXME: most of the code
  5024.          below is repeated several times, can we extract the common parts
  5025.          and place them into a subroutine or something similar?  */
  5026.       /* FIXME Is this (and the next IF stmt) really right?
  5027.      What if INPUT_LINE_POINTER points to "$TEXT$FOO"?  */
  5028.       if (strncmp (input_line_pointer, "$TEXT$", 6) == 0)
  5029.     {
  5030.       input_line_pointer += 6;
  5031.       sd_chain = is_defined_space ("$TEXT$");
  5032.       if (sd_chain == NULL)
  5033.         sd_chain = pa_parse_space_stmt ("$TEXT$", 1);
  5034.       else if (SPACE_USER_DEFINED (sd_chain) == 0)
  5035.         sd_chain = pa_parse_space_stmt ("$TEXT$", 0);
  5036.  
  5037.       current_space = sd_chain;
  5038.       subseg_set (text_section, sd_chain->sd_last_subseg);
  5039.       current_subspace
  5040.         = pa_subsegment_to_subspace (text_section,
  5041.                      sd_chain->sd_last_subseg);
  5042.       demand_empty_rest_of_line ();
  5043.       return;
  5044.     }
  5045.       if (strncmp (input_line_pointer, "$PRIVATE$", 9) == 0)
  5046.     {
  5047.       input_line_pointer += 9;
  5048.       sd_chain = is_defined_space ("$PRIVATE$");
  5049.       if (sd_chain == NULL)
  5050.         sd_chain = pa_parse_space_stmt ("$PRIVATE$", 1);
  5051.       else if (SPACE_USER_DEFINED (sd_chain) == 0)
  5052.         sd_chain = pa_parse_space_stmt ("$PRIVATE$", 0);
  5053.  
  5054.       current_space = sd_chain;
  5055.       subseg_set (data_section, sd_chain->sd_last_subseg);
  5056.       current_subspace
  5057.         = pa_subsegment_to_subspace (data_section,
  5058.                      sd_chain->sd_last_subseg);
  5059.       demand_empty_rest_of_line ();
  5060.       return;
  5061.     }
  5062.       if (!strncasecmp (input_line_pointer,
  5063.             GDB_DEBUG_SPACE_NAME,
  5064.             strlen (GDB_DEBUG_SPACE_NAME)))
  5065.     {
  5066.       input_line_pointer += strlen (GDB_DEBUG_SPACE_NAME);
  5067.       sd_chain = is_defined_space (GDB_DEBUG_SPACE_NAME);
  5068.       if (sd_chain == NULL)
  5069.         sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 1);
  5070.       else if (SPACE_USER_DEFINED (sd_chain) == 0)
  5071.         sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 0);
  5072.  
  5073.       current_space = sd_chain;
  5074.  
  5075.       {
  5076.         asection *gdb_section
  5077.         = bfd_make_section_old_way (stdoutput, GDB_DEBUG_SPACE_NAME);
  5078.  
  5079.         subseg_set (gdb_section, sd_chain->sd_last_subseg);
  5080.         current_subspace
  5081.           = pa_subsegment_to_subspace (gdb_section,
  5082.                        sd_chain->sd_last_subseg);
  5083.       }
  5084.       demand_empty_rest_of_line ();
  5085.       return;
  5086.     }
  5087.  
  5088.       /* It could be a space specified by number.  */
  5089.       print_errors = 0;
  5090.       save_s = input_line_pointer;
  5091.       if ((temp = pa_parse_number (&input_line_pointer, 0)) >= 0)
  5092.     {
  5093.       if ((sd_chain = pa_find_space_by_number (temp)))
  5094.         {
  5095.           current_space = sd_chain;
  5096.  
  5097.           subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
  5098.           current_subspace
  5099.         = pa_subsegment_to_subspace (sd_chain->sd_seg,
  5100.                          sd_chain->sd_last_subseg);
  5101.           demand_empty_rest_of_line ();
  5102.           return;
  5103.         }
  5104.     }
  5105.  
  5106.       /* Not a number, attempt to create a new space.  */
  5107.       print_errors = 1;
  5108.       input_line_pointer = save_s;
  5109.       name = input_line_pointer;
  5110.       c = get_symbol_end ();
  5111.       space_name = xmalloc (strlen (name) + 1);
  5112.       strcpy (space_name, name);
  5113.       *input_line_pointer = c;
  5114.  
  5115.       sd_chain = pa_parse_space_stmt (space_name, 1);
  5116.       current_space = sd_chain;
  5117.  
  5118.       subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
  5119.       current_subspace = pa_subsegment_to_subspace (sd_chain->sd_seg,
  5120.                           sd_chain->sd_last_subseg);
  5121.       demand_empty_rest_of_line ();
  5122.     }
  5123. }
  5124.  
  5125. /* Switch to a new space.  (I think).  FIXME.  */
  5126.  
  5127. static void
  5128. pa_spnum (unused)
  5129.      int unused;
  5130. {
  5131.   char *name;
  5132.   char c;
  5133.   char *p;
  5134.   sd_chain_struct *space;
  5135.  
  5136.   name = input_line_pointer;
  5137.   c = get_symbol_end ();
  5138.   space = is_defined_space (name);
  5139.   if (space)
  5140.     {
  5141.       p = frag_more (4);
  5142.       md_number_to_chars (p, SPACE_SPNUM (space), 4);
  5143.     }
  5144.   else
  5145.     as_warn ("Undefined space: '%s' Assuming space number = 0.", name);
  5146.  
  5147.   *input_line_pointer = c;
  5148.   demand_empty_rest_of_line ();
  5149. }
  5150.  
  5151. /* If VALUE is an exact power of two between zero and 2^31, then
  5152.    return log2 (VALUE).  Else return -1.  */
  5153.  
  5154. static int
  5155. log2 (value)
  5156.      int value;
  5157. {
  5158.   int shift = 0;
  5159.  
  5160.   while ((1 << shift) != value && shift < 32)
  5161.     shift++;
  5162.  
  5163.   if (shift >= 32)
  5164.     return -1;
  5165.   else
  5166.     return shift;
  5167. }
  5168.  
  5169. /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
  5170.    given subspace, creating the new subspace if necessary.
  5171.  
  5172.    FIXME.  Should mirror pa_space more closely, in particular how
  5173.    they're broken up into subroutines.  */
  5174.  
  5175. static void
  5176. pa_subspace (unused)
  5177.      int unused;
  5178. {
  5179.   char *name, *ss_name, *alias, c;
  5180.   char loadable, code_only, common, dup_common, zero, sort;
  5181.   int i, access, space_index, alignment, quadrant, applicable, flags;
  5182.   sd_chain_struct *space;
  5183.   ssd_chain_struct *ssd;
  5184.   asection *section;
  5185.  
  5186.   if (within_procedure)
  5187.     {
  5188.       as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
  5189.       ignore_rest_of_line ();
  5190.     }
  5191.   else
  5192.     {
  5193.       name = input_line_pointer;
  5194.       c = get_symbol_end ();
  5195.       ss_name = xmalloc (strlen (name) + 1);
  5196.       strcpy (ss_name, name);
  5197.       *input_line_pointer = c;
  5198.  
  5199.       /* Load default values.  */
  5200.       sort = 0;
  5201.       access = 0x7f;
  5202.       loadable = 1;
  5203.       common = 0;
  5204.       dup_common = 0;
  5205.       code_only = 0;
  5206.       zero = 0;
  5207.       space_index = ~0;
  5208.       alignment = 0;
  5209.       quadrant = 0;
  5210.       alias = NULL;
  5211.  
  5212.       space = current_space;
  5213.       ssd = is_defined_subspace (ss_name);
  5214.       /* Allow user to override the builtin attributes of subspaces.  But
  5215.          only allow the attributes to be changed once!  */
  5216.       if (ssd && SUBSPACE_DEFINED (ssd))
  5217.     {
  5218.       subseg_set (ssd->ssd_seg, ssd->ssd_subseg);
  5219.       if (!is_end_of_statement ())
  5220.         as_warn ("Parameters of an existing subspace can\'t be modified");
  5221.       demand_empty_rest_of_line ();
  5222.       return;
  5223.     }
  5224.       else
  5225.     {
  5226.       /* A new subspace.  Load default values if it matches one of
  5227.          the builtin subspaces.  */
  5228.       i = 0;
  5229.       while (pa_def_subspaces[i].name)
  5230.         {
  5231.           if (strcasecmp (pa_def_subspaces[i].name, ss_name) == 0)
  5232.         {
  5233.           loadable = pa_def_subspaces[i].loadable;
  5234.           common = pa_def_subspaces[i].common;
  5235.           dup_common = pa_def_subspaces[i].dup_common;
  5236.           code_only = pa_def_subspaces[i].code_only;
  5237.           zero = pa_def_subspaces[i].zero;
  5238.           space_index = pa_def_subspaces[i].space_index;
  5239.           alignment = pa_def_subspaces[i].alignment;
  5240.           quadrant = pa_def_subspaces[i].quadrant;
  5241.           access = pa_def_subspaces[i].access;
  5242.           sort = pa_def_subspaces[i].sort;
  5243.           if (USE_ALIASES && pa_def_subspaces[i].alias)
  5244.             alias = pa_def_subspaces[i].alias;
  5245.           break;
  5246.         }
  5247.           i++;
  5248.         }
  5249.     }
  5250.  
  5251.       /* We should be working with a new subspace now.  Fill in
  5252.          any information as specified by the user.  */
  5253.       if (!is_end_of_statement ())
  5254.     {
  5255.       input_line_pointer++;
  5256.       while (!is_end_of_statement ())
  5257.         {
  5258.           name = input_line_pointer;
  5259.           c = get_symbol_end ();
  5260.           if ((strncasecmp (name, "quad", 4) == 0))
  5261.         {
  5262.           *input_line_pointer = c;
  5263.           input_line_pointer++;
  5264.           quadrant = get_absolute_expression ();
  5265.         }
  5266.           else if ((strncasecmp (name, "align", 5) == 0))
  5267.         {
  5268.           *input_line_pointer = c;
  5269.           input_line_pointer++;
  5270.           alignment = get_absolute_expression ();
  5271.           if (log2 (alignment) == -1)
  5272.             {
  5273.               as_bad ("Alignment must be a power of 2");
  5274.               alignment = 1;
  5275.             }
  5276.         }
  5277.           else if ((strncasecmp (name, "access", 6) == 0))
  5278.         {
  5279.           *input_line_pointer = c;
  5280.           input_line_pointer++;
  5281.           access = get_absolute_expression ();
  5282.         }
  5283.           else if ((strncasecmp (name, "sort", 4) == 0))
  5284.         {
  5285.           *input_line_pointer = c;
  5286.           input_line_pointer++;
  5287.           sort = get_absolute_expression ();
  5288.         }
  5289.           else if ((strncasecmp (name, "code_only", 9) == 0))
  5290.         {
  5291.           *input_line_pointer = c;
  5292.           code_only = 1;
  5293.         }
  5294.           else if ((strncasecmp (name, "unloadable", 10) == 0))
  5295.         {
  5296.           *input_line_pointer = c;
  5297.           loadable = 0;
  5298.         }
  5299.           else if ((strncasecmp (name, "common", 6) == 0))
  5300.         {
  5301.           *input_line_pointer = c;
  5302.           common = 1;
  5303.         }
  5304.           else if ((strncasecmp (name, "dup_comm", 8) == 0))
  5305.         {
  5306.           *input_line_pointer = c;
  5307.           dup_common = 1;
  5308.         }
  5309.           else if ((strncasecmp (name, "zero", 4) == 0))
  5310.         {
  5311.           *input_line_pointer = c;
  5312.           zero = 1;
  5313.         }
  5314.           else if ((strncasecmp (name, "first", 5) == 0))
  5315.         as_bad ("FIRST not supported as a .SUBSPACE argument");
  5316.           else
  5317.         as_bad ("Invalid .SUBSPACE argument");
  5318.           if (!is_end_of_statement ())
  5319.         input_line_pointer++;
  5320.         }
  5321.     }
  5322.  
  5323.       /* Compute a reasonable set of BFD flags based on the information
  5324.          in the .subspace directive.  */
  5325.       applicable = bfd_applicable_section_flags (stdoutput);
  5326.       flags = 0;
  5327.       if (loadable)
  5328.     flags |= (SEC_ALLOC | SEC_LOAD);
  5329.       if (code_only)
  5330.     flags |= SEC_CODE;
  5331.       if (common || dup_common)
  5332.     flags |= SEC_IS_COMMON;
  5333.  
  5334.       /* This is a zero-filled subspace (eg BSS).  */
  5335.       if (zero)
  5336.     flags &= ~SEC_LOAD;
  5337.  
  5338.       flags |= SEC_RELOC | SEC_HAS_CONTENTS;
  5339.       applicable &= flags;
  5340.  
  5341.       /* If this is an existing subspace, then we want to use the
  5342.          segment already associated with the subspace.
  5343.  
  5344.          FIXME NOW!  ELF BFD doesn't appear to be ready to deal with
  5345.          lots of sections.  It might be a problem in the PA ELF
  5346.          code, I do not know yet.  For now avoid creating anything
  5347.          but the "standard" sections for ELF.  */
  5348.       if (ssd)
  5349.     section = ssd->ssd_seg;
  5350.       else if (alias)
  5351.     section = subseg_new (alias, 0);
  5352.       else if (!alias && USE_ALIASES)
  5353.     {
  5354.       as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
  5355.       demand_empty_rest_of_line ();
  5356.       return;
  5357.     }
  5358.       else
  5359.     section = subseg_new (ss_name, 0);
  5360.  
  5361.       /* Now set the flags.  */
  5362.       bfd_set_section_flags (stdoutput, section, applicable);
  5363.  
  5364.       /* Record any alignment request for this section.  */
  5365.       record_alignment (section, log2 (alignment));
  5366.  
  5367.       /* Set the starting offset for this section.  */
  5368.       bfd_set_section_vma (stdoutput, section,
  5369.                pa_subspace_start (space, quadrant));
  5370.  
  5371.       /* Now that all the flags are set, update an existing subspace,
  5372.          or create a new one.  */
  5373.       if (ssd)
  5374.  
  5375.     current_subspace = update_subspace (space, ss_name, loadable,
  5376.                         code_only, common, dup_common,
  5377.                         sort, zero, access, space_index,
  5378.                         alignment, quadrant,
  5379.                         section);
  5380.       else
  5381.     current_subspace = create_new_subspace (space, ss_name, loadable,
  5382.                         code_only, common,
  5383.                         dup_common, zero, sort,
  5384.                         access, space_index,
  5385.                           alignment, quadrant, section);
  5386.  
  5387.       demand_empty_rest_of_line ();
  5388.       current_subspace->ssd_seg = section;
  5389.       subseg_set (current_subspace->ssd_seg, current_subspace->ssd_subseg);
  5390.     }
  5391.   SUBSPACE_DEFINED (current_subspace) = 1;
  5392. }
  5393.  
  5394.  
  5395. /* Create default space and subspace dictionaries.  */
  5396.  
  5397. static void
  5398. pa_spaces_begin ()
  5399. {
  5400.   int i;
  5401.  
  5402.   space_dict_root = NULL;
  5403.   space_dict_last = NULL;
  5404.  
  5405.   i = 0;
  5406.   while (pa_def_spaces[i].name)
  5407.     {
  5408.       char *name;
  5409.  
  5410.       /* Pick the right name to use for the new section.  */
  5411.       if (pa_def_spaces[i].alias && USE_ALIASES)
  5412.     name = pa_def_spaces[i].alias;
  5413.       else
  5414.     name = pa_def_spaces[i].name;
  5415.  
  5416.       pa_def_spaces[i].segment = subseg_new (name, 0);
  5417.       create_new_space (pa_def_spaces[i].name, pa_def_spaces[i].spnum,
  5418.             pa_def_spaces[i].loadable, pa_def_spaces[i].defined,
  5419.             pa_def_spaces[i].private, pa_def_spaces[i].sort,
  5420.             pa_def_spaces[i].segment, 0);
  5421.       i++;
  5422.     }
  5423.  
  5424.   i = 0;
  5425.   while (pa_def_subspaces[i].name)
  5426.     {
  5427.       char *name;
  5428.       int applicable, subsegment;
  5429.       asection *segment = NULL;
  5430.       sd_chain_struct *space;
  5431.  
  5432.       /* Pick the right name for the new section and pick the right
  5433.          subsegment number.  */
  5434.       if (pa_def_subspaces[i].alias && USE_ALIASES)
  5435.     {
  5436.       name = pa_def_subspaces[i].alias;
  5437.       subsegment = pa_def_subspaces[i].subsegment;
  5438.     }
  5439.       else
  5440.     {
  5441.       name = pa_def_subspaces[i].name;
  5442.       subsegment = 0;
  5443.     }
  5444.  
  5445.       /* Create the new section.  */
  5446.       segment = subseg_new (name, subsegment);
  5447.  
  5448.  
  5449.       /* For SOM we want to replace the standard .text, .data, and .bss
  5450.          sections with our own.   We also want to set BFD flags for
  5451.      all the built-in subspaces.  */
  5452.       if (!strcmp (pa_def_subspaces[i].name, "$CODE$") && !USE_ALIASES)
  5453.     {
  5454.       text_section = segment;
  5455.       applicable = bfd_applicable_section_flags (stdoutput);
  5456.       bfd_set_section_flags (stdoutput, segment,
  5457.                  applicable & (SEC_ALLOC | SEC_LOAD
  5458.                            | SEC_RELOC | SEC_CODE
  5459.                            | SEC_READONLY
  5460.                            | SEC_HAS_CONTENTS));
  5461.     }
  5462.       else if (!strcmp (pa_def_subspaces[i].name, "$DATA$") && !USE_ALIASES)
  5463.     {
  5464.       data_section = segment;
  5465.       applicable = bfd_applicable_section_flags (stdoutput);
  5466.       bfd_set_section_flags (stdoutput, segment,
  5467.                  applicable & (SEC_ALLOC | SEC_LOAD
  5468.                            | SEC_RELOC
  5469.                            | SEC_HAS_CONTENTS));
  5470.  
  5471.  
  5472.     }
  5473.       else if (!strcmp (pa_def_subspaces[i].name, "$BSS$") && !USE_ALIASES)
  5474.     {
  5475.       bss_section = segment;
  5476.       applicable = bfd_applicable_section_flags (stdoutput);
  5477.       bfd_set_section_flags (stdoutput, segment,
  5478.                  applicable & SEC_ALLOC);
  5479.     }
  5480.       else if (!strcmp (pa_def_subspaces[i].name, "$LIT$") && !USE_ALIASES)
  5481.     {
  5482.       applicable = bfd_applicable_section_flags (stdoutput);
  5483.       bfd_set_section_flags (stdoutput, segment,
  5484.                  applicable & (SEC_ALLOC | SEC_LOAD
  5485.                            | SEC_RELOC
  5486.                            | SEC_READONLY
  5487.                            | SEC_HAS_CONTENTS));
  5488.     }
  5489.       else if (!strcmp (pa_def_subspaces[i].name, "$UNWIND$") && !USE_ALIASES)
  5490.     {
  5491.       applicable = bfd_applicable_section_flags (stdoutput);
  5492.       bfd_set_section_flags (stdoutput, segment,
  5493.                  applicable & (SEC_ALLOC | SEC_LOAD
  5494.                            | SEC_RELOC
  5495.                            | SEC_READONLY
  5496.                            | SEC_HAS_CONTENTS));
  5497.     }
  5498.  
  5499.       /* Find the space associated with this subspace.  */
  5500.       space = pa_segment_to_space (pa_def_spaces[pa_def_subspaces[i].
  5501.                          def_space_index].segment);
  5502.       if (space == NULL)
  5503.     {
  5504.       as_fatal ("Internal error: Unable to find containing space for %s.",
  5505.             pa_def_subspaces[i].name);
  5506.     }
  5507.  
  5508.       create_new_subspace (space, name,
  5509.                pa_def_subspaces[i].loadable,
  5510.                pa_def_subspaces[i].code_only,
  5511.                pa_def_subspaces[i].common,
  5512.                pa_def_subspaces[i].dup_common,
  5513.                pa_def_subspaces[i].zero,
  5514.                pa_def_subspaces[i].sort,
  5515.                pa_def_subspaces[i].access,
  5516.                pa_def_subspaces[i].space_index,
  5517.                pa_def_subspaces[i].alignment,
  5518.                pa_def_subspaces[i].quadrant,
  5519.                segment);
  5520.       i++;
  5521.     }
  5522. }
  5523.  
  5524.  
  5525.  
  5526. /* Create a new space NAME, with the appropriate flags as defined
  5527.    by the given parameters.  */
  5528.  
  5529. static sd_chain_struct *
  5530. create_new_space (name, spnum, loadable, defined, private,
  5531.           sort, seg, user_defined)
  5532.      char *name;
  5533.      int spnum;
  5534.      int loadable;
  5535.      int defined;
  5536.      int private;
  5537.      int sort;
  5538.      asection *seg;
  5539.      int user_defined;
  5540. {
  5541.   sd_chain_struct *chain_entry;
  5542.  
  5543.   chain_entry = (sd_chain_struct *) xmalloc (sizeof (sd_chain_struct));
  5544.   if (!chain_entry)
  5545.     as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
  5546.           name);
  5547.  
  5548.   SPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
  5549.   strcpy (SPACE_NAME (chain_entry), name);
  5550.   SPACE_DEFINED (chain_entry) = defined;
  5551.   SPACE_USER_DEFINED (chain_entry) = user_defined;
  5552.   SPACE_SPNUM (chain_entry) = spnum;
  5553.  
  5554.   chain_entry->sd_seg = seg;
  5555.   chain_entry->sd_last_subseg = -1;
  5556.   chain_entry->sd_subspaces = NULL;
  5557.   chain_entry->sd_next = NULL;
  5558.  
  5559.   /* Find spot for the new space based on its sort key.  */
  5560.   if (!space_dict_last)
  5561.     space_dict_last = chain_entry;
  5562.  
  5563.   if (space_dict_root == NULL)
  5564.     space_dict_root = chain_entry;
  5565.   else
  5566.     {
  5567.       sd_chain_struct *chain_pointer;
  5568.       sd_chain_struct *prev_chain_pointer;
  5569.  
  5570.       chain_pointer = space_dict_root;
  5571.       prev_chain_pointer = NULL;
  5572.  
  5573.       while (chain_pointer)
  5574.     {
  5575.       prev_chain_pointer = chain_pointer;
  5576.       chain_pointer = chain_pointer->sd_next;
  5577.     }
  5578.  
  5579.       /* At this point we've found the correct place to add the new
  5580.          entry.  So add it and update the linked lists as appropriate.  */
  5581.       if (prev_chain_pointer)
  5582.     {
  5583.       chain_entry->sd_next = chain_pointer;
  5584.       prev_chain_pointer->sd_next = chain_entry;
  5585.     }
  5586.       else
  5587.     {
  5588.       space_dict_root = chain_entry;
  5589.       chain_entry->sd_next = chain_pointer;
  5590.     }
  5591.  
  5592.       if (chain_entry->sd_next == NULL)
  5593.     space_dict_last = chain_entry;
  5594.     }
  5595.  
  5596.   /* This is here to catch predefined spaces which do not get
  5597.      modified by the user's input.  Another call is found at
  5598.      the bottom of pa_parse_space_stmt to handle cases where
  5599.      the user modifies a predefined space.  */
  5600. #ifdef obj_set_section_attributes
  5601.   obj_set_section_attributes (seg, defined, private, sort, spnum);
  5602. #endif
  5603.  
  5604.   return chain_entry;
  5605. }
  5606.  
  5607. /* Create a new subspace NAME, with the appropriate flags as defined
  5608.    by the given parameters.
  5609.  
  5610.    Add the new subspace to the subspace dictionary chain in numerical
  5611.    order as defined by the SORT entries.  */
  5612.  
  5613. static ssd_chain_struct *
  5614. create_new_subspace (space, name, loadable, code_only, common,
  5615.              dup_common, is_zero, sort, access, space_index,
  5616.              alignment, quadrant, seg)
  5617.      sd_chain_struct *space;
  5618.      char *name;
  5619.      int loadable, code_only, common, dup_common, is_zero;
  5620.      int sort;
  5621.      int access;
  5622.      int space_index;
  5623.      int alignment;
  5624.      int quadrant;
  5625.      asection *seg;
  5626. {
  5627.   ssd_chain_struct *chain_entry;
  5628.  
  5629.   chain_entry = (ssd_chain_struct *) xmalloc (sizeof (ssd_chain_struct));
  5630.   if (!chain_entry)
  5631.     as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name);
  5632.  
  5633.   SUBSPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
  5634.   strcpy (SUBSPACE_NAME (chain_entry), name);
  5635.  
  5636.   /* Initialize subspace_defined.  When we hit a .subspace directive
  5637.      we'll set it to 1 which "locks-in" the subspace attributes.  */
  5638.   SUBSPACE_DEFINED (chain_entry) = 0;
  5639.  
  5640.   chain_entry->ssd_subseg = USE_ALIASES ? pa_next_subseg (space) : 0;
  5641.   chain_entry->ssd_seg = seg;
  5642.   chain_entry->ssd_next = NULL;
  5643.  
  5644.   /* Find spot for the new subspace based on its sort key.  */
  5645.   if (space->sd_subspaces == NULL)
  5646.     space->sd_subspaces = chain_entry;
  5647.   else
  5648.     {
  5649.       ssd_chain_struct *chain_pointer;
  5650.       ssd_chain_struct *prev_chain_pointer;
  5651.  
  5652.       chain_pointer = space->sd_subspaces;
  5653.       prev_chain_pointer = NULL;
  5654.  
  5655.       while (chain_pointer)
  5656.     {
  5657.       prev_chain_pointer = chain_pointer;
  5658.       chain_pointer = chain_pointer->ssd_next;
  5659.     }
  5660.  
  5661.       /* Now we have somewhere to put the new entry.  Insert it and update
  5662.          the links.  */
  5663.       if (prev_chain_pointer)
  5664.     {
  5665.       chain_entry->ssd_next = chain_pointer;
  5666.       prev_chain_pointer->ssd_next = chain_entry;
  5667.     }
  5668.       else
  5669.     {
  5670.       space->sd_subspaces = chain_entry;
  5671.       chain_entry->ssd_next = chain_pointer;
  5672.     }
  5673.     }
  5674.  
  5675. #ifdef obj_set_subsection_attributes
  5676.   obj_set_subsection_attributes (seg, space->sd_seg, access,
  5677.                  sort, quadrant);
  5678. #endif
  5679.  
  5680.   return chain_entry;
  5681. }
  5682.  
  5683. /* Update the information for the given subspace based upon the
  5684.    various arguments.   Return the modified subspace chain entry.  */
  5685.  
  5686. static ssd_chain_struct *
  5687. update_subspace (space, name, loadable, code_only, common, dup_common, sort,
  5688.          zero, access, space_index, alignment, quadrant, section)
  5689.      sd_chain_struct *space;
  5690.      char *name;
  5691.      int loadable;
  5692.      int code_only;
  5693.      int common;
  5694.      int dup_common;
  5695.      int zero;
  5696.      int sort;
  5697.      int access;
  5698.      int space_index;
  5699.      int alignment;
  5700.      int quadrant;
  5701.      asection *section;
  5702. {
  5703.   ssd_chain_struct *chain_entry;
  5704.  
  5705.   chain_entry = is_defined_subspace (name);
  5706.  
  5707. #ifdef obj_set_subsection_attributes
  5708.   obj_set_subsection_attributes (section, space->sd_seg, access,
  5709.                  sort, quadrant);
  5710. #endif
  5711.  
  5712.   return chain_entry;
  5713. }
  5714.  
  5715. /* Return the space chain entry for the space with the name NAME or
  5716.    NULL if no such space exists.  */
  5717.  
  5718. static sd_chain_struct *
  5719. is_defined_space (name)
  5720.      char *name;
  5721. {
  5722.   sd_chain_struct *chain_pointer;
  5723.  
  5724.   for (chain_pointer = space_dict_root;
  5725.        chain_pointer;
  5726.        chain_pointer = chain_pointer->sd_next)
  5727.     {
  5728.       if (strcmp (SPACE_NAME (chain_pointer), name) == 0)
  5729.     return chain_pointer;
  5730.     }
  5731.  
  5732.   /* No mapping from segment to space was found.  Return NULL.  */
  5733.   return NULL;
  5734. }
  5735.  
  5736. /* Find and return the space associated with the given seg.  If no mapping
  5737.    from the given seg to a space is found, then return NULL.
  5738.  
  5739.    Unlike subspaces, the number of spaces is not expected to grow much,
  5740.    so a linear exhaustive search is OK here.  */
  5741.  
  5742. static sd_chain_struct *
  5743. pa_segment_to_space (seg)
  5744.      asection *seg;
  5745. {
  5746.   sd_chain_struct *space_chain;
  5747.  
  5748.   /* Walk through each space looking for the correct mapping.  */
  5749.   for (space_chain = space_dict_root;
  5750.        space_chain;
  5751.        space_chain = space_chain->sd_next)
  5752.     {
  5753.       if (space_chain->sd_seg == seg)
  5754.     return space_chain;
  5755.     }
  5756.  
  5757.   /* Mapping was not found.  Return NULL.  */
  5758.   return NULL;
  5759. }
  5760.  
  5761. /* Return the space chain entry for the subspace with the name NAME or
  5762.    NULL if no such subspace exists.
  5763.  
  5764.    Uses a linear search through all the spaces and subspaces, this may
  5765.    not be appropriate if we ever being placing each function in its
  5766.    own subspace.  */
  5767.  
  5768. static ssd_chain_struct *
  5769. is_defined_subspace (name)
  5770.      char *name;
  5771. {
  5772.   sd_chain_struct *space_chain;
  5773.   ssd_chain_struct *subspace_chain;
  5774.  
  5775.   /* Walk through each space.  */
  5776.   for (space_chain = space_dict_root;
  5777.        space_chain;
  5778.        space_chain = space_chain->sd_next)
  5779.     {
  5780.       /* Walk through each subspace looking for a name which matches.  */
  5781.       for (subspace_chain = space_chain->sd_subspaces;
  5782.        subspace_chain;
  5783.        subspace_chain = subspace_chain->ssd_next)
  5784.     if (strcmp (SUBSPACE_NAME (subspace_chain), name) == 0)
  5785.       return subspace_chain;
  5786.     }
  5787.  
  5788.   /* Subspace wasn't found.  Return NULL.  */
  5789.   return NULL;
  5790. }
  5791.  
  5792. /* Find and return the subspace associated with the given seg.  If no
  5793.    mapping from the given seg to a subspace is found, then return NULL.
  5794.  
  5795.    If we ever put each procedure/function within its own subspace
  5796.    (to make life easier on the compiler and linker), then this will have
  5797.    to become more efficient.  */
  5798.  
  5799. static ssd_chain_struct *
  5800. pa_subsegment_to_subspace (seg, subseg)
  5801.      asection *seg;
  5802.      subsegT subseg;
  5803. {
  5804.   sd_chain_struct *space_chain;
  5805.   ssd_chain_struct *subspace_chain;
  5806.  
  5807.   /* Walk through each space.  */
  5808.   for (space_chain = space_dict_root;
  5809.        space_chain;
  5810.        space_chain = space_chain->sd_next)
  5811.     {
  5812.       if (space_chain->sd_seg == seg)
  5813.     {
  5814.       /* Walk through each subspace within each space looking for
  5815.          the correct mapping.  */
  5816.       for (subspace_chain = space_chain->sd_subspaces;
  5817.            subspace_chain;
  5818.            subspace_chain = subspace_chain->ssd_next)
  5819.         if (subspace_chain->ssd_subseg == (int) subseg)
  5820.           return subspace_chain;
  5821.     }
  5822.     }
  5823.  
  5824.   /* No mapping from subsegment to subspace found.  Return NULL.  */
  5825.   return NULL;
  5826. }
  5827.  
  5828. /* Given a number, try and find a space with the name number.
  5829.  
  5830.    Return a pointer to a space dictionary chain entry for the space
  5831.    that was found or NULL on failure.  */
  5832.  
  5833. static sd_chain_struct *
  5834. pa_find_space_by_number (number)
  5835.      int number;
  5836. {
  5837.   sd_chain_struct *space_chain;
  5838.  
  5839.   for (space_chain = space_dict_root;
  5840.        space_chain;
  5841.        space_chain = space_chain->sd_next)
  5842.     {
  5843.       if (SPACE_SPNUM (space_chain) == number)
  5844.     return space_chain;
  5845.     }
  5846.  
  5847.   /* No appropriate space found.  Return NULL.  */
  5848.   return NULL;
  5849. }
  5850.  
  5851. /* Return the starting address for the given subspace.  If the starting
  5852.    address is unknown then return zero.  */
  5853.  
  5854. static unsigned int
  5855. pa_subspace_start (space, quadrant)
  5856.      sd_chain_struct *space;
  5857.      int quadrant;
  5858. {
  5859.   /* FIXME.  Assumes everyone puts read/write data at 0x4000000, this
  5860.      is not correct for the PA OSF1 port.  */
  5861.   if ((strcmp (SPACE_NAME (space), "$PRIVATE$") == 0) && quadrant == 1)
  5862.     return 0x40000000;
  5863.   else if (space->sd_seg == data_section && quadrant == 1)
  5864.     return 0x40000000;
  5865.   else
  5866.     return 0;
  5867. }
  5868.  
  5869. /* FIXME.  Needs documentation.  */
  5870. static int
  5871. pa_next_subseg (space)
  5872.      sd_chain_struct *space;
  5873. {
  5874.  
  5875.   space->sd_last_subseg++;
  5876.   return space->sd_last_subseg;
  5877. }
  5878.  
  5879. /* Helper function for pa_stringer.  Used to find the end of
  5880.    a string.  */
  5881.  
  5882. static unsigned int
  5883. pa_stringer_aux (s)
  5884.      char *s;
  5885. {
  5886.   unsigned int c = *s & CHAR_MASK;
  5887.   switch (c)
  5888.     {
  5889.     case '\"':
  5890.       c = NOT_A_CHAR;
  5891.       break;
  5892.     default:
  5893.       break;
  5894.     }
  5895.   return c;
  5896. }
  5897.  
  5898. /* Handle a .STRING type pseudo-op.  */
  5899.  
  5900. static void
  5901. pa_stringer (append_zero)
  5902.      int append_zero;
  5903. {
  5904.   char *s, num_buf[4];
  5905.   unsigned int c;
  5906.   int i;
  5907.  
  5908.   /* Preprocess the string to handle PA-specific escape sequences.
  5909.      For example, \xDD where DD is a hexidecimal number should be
  5910.      changed to \OOO where OOO is an octal number.  */
  5911.  
  5912.   /* Skip the opening quote.  */
  5913.   s = input_line_pointer + 1;
  5914.  
  5915.   while (is_a_char (c = pa_stringer_aux (s++)))
  5916.     {
  5917.       if (c == '\\')
  5918.     {
  5919.       c = *s;
  5920.       switch (c)
  5921.         {
  5922.           /* Handle \x<num>.  */
  5923.         case 'x':
  5924.           {
  5925.         unsigned int number;
  5926.         int num_digit;
  5927.         char dg;
  5928.         char *s_start = s;
  5929.  
  5930.         /* Get pas the 'x'.  */
  5931.         s++;
  5932.         for (num_digit = 0, number = 0, dg = *s;
  5933.              num_digit < 2
  5934.              && (isdigit (dg) || (dg >= 'a' && dg <= 'f')
  5935.              || (dg >= 'A' && dg <= 'F'));
  5936.              num_digit++)
  5937.           {
  5938.             if (isdigit (dg))
  5939.               number = number * 16 + dg - '0';
  5940.             else if (dg >= 'a' && dg <= 'f')
  5941.               number = number * 16 + dg - 'a' + 10;
  5942.             else
  5943.               number = number * 16 + dg - 'A' + 10;
  5944.  
  5945.             s++;
  5946.             dg = *s;
  5947.           }
  5948.         if (num_digit > 0)
  5949.           {
  5950.             switch (num_digit)
  5951.               {
  5952.               case 1:
  5953.             sprintf (num_buf, "%02o", number);
  5954.             break;
  5955.               case 2:
  5956.             sprintf (num_buf, "%03o", number);
  5957.             break;
  5958.               }
  5959.             for (i = 0; i <= num_digit; i++)
  5960.               s_start[i] = num_buf[i];
  5961.           }
  5962.         break;
  5963.           }
  5964.         /* This might be a "\"", skip over the escaped char.  */
  5965.         default:
  5966.           s++;
  5967.           break;
  5968.         }
  5969.     }
  5970.     }
  5971.   stringer (append_zero);
  5972.   pa_undefine_label ();
  5973. }
  5974.  
  5975. /* Handle a .VERSION pseudo-op.  */
  5976.  
  5977. static void
  5978. pa_version (unused)
  5979.      int unused;
  5980. {
  5981.   obj_version (0);
  5982.   pa_undefine_label ();
  5983. }
  5984.  
  5985. /* Handle a .COPYRIGHT pseudo-op.  */
  5986.  
  5987. static void
  5988. pa_copyright (unused)
  5989.      int unused;
  5990. {
  5991.   obj_copyright (0);
  5992.   pa_undefine_label ();
  5993. }
  5994.  
  5995. /* Just like a normal cons, but when finished we have to undefine
  5996.    the latest space label.  */
  5997.  
  5998. static void
  5999. pa_cons (nbytes)
  6000.      int nbytes;
  6001. {
  6002.   cons (nbytes);
  6003.   pa_undefine_label ();
  6004. }
  6005.  
  6006. /* Switch to the data space.  As usual delete our label.  */
  6007.  
  6008. static void
  6009. pa_data (unused)
  6010.      int unused;
  6011. {
  6012.   s_data (0);
  6013.   pa_undefine_label ();
  6014. }
  6015.  
  6016. /* Like float_cons, but we need to undefine our label.  */
  6017.  
  6018. static void
  6019. pa_float_cons (float_type)
  6020.      int float_type;
  6021. {
  6022.   float_cons (float_type);
  6023.   pa_undefine_label ();
  6024. }
  6025.  
  6026. /* Like s_fill, but delete our label when finished.  */
  6027.  
  6028. static void
  6029. pa_fill (unused)
  6030.      int unused;
  6031. {
  6032.   s_fill (0);
  6033.   pa_undefine_label ();
  6034. }
  6035.  
  6036. /* Like lcomm, but delete our label when finished.  */
  6037.  
  6038. static void
  6039. pa_lcomm (needs_align)
  6040.      int needs_align;
  6041. {
  6042.   s_lcomm (needs_align);
  6043.   pa_undefine_label ();
  6044. }
  6045.  
  6046. /* Like lsym, but delete our label when finished.  */
  6047.  
  6048. static void
  6049. pa_lsym (unused)
  6050.      int unused;
  6051. {
  6052.   s_lsym (0);
  6053.   pa_undefine_label ();
  6054. }
  6055.  
  6056. /* Switch to the text space.  Like s_text, but delete our
  6057.    label when finished.  */
  6058. static void
  6059. pa_text (unused)
  6060.      int unused;
  6061. {
  6062.   s_text (0);
  6063.   pa_undefine_label ();
  6064. }
  6065.  
  6066. /* On the PA relocations which involve function symbols must not be
  6067.    adjusted.  This so that the linker can know when/how to create argument
  6068.    relocation stubs for indirect calls and calls to static functions.
  6069.  
  6070.    "T" field selectors create DLT relative fixups for accessing
  6071.    globals and statics in PIC code; each DLT relative fixup creates
  6072.    an entry in the DLT table.  The entries contain the address of
  6073.    the final target (eg accessing "foo" would create a DLT entry
  6074.    with the address of "foo").
  6075.  
  6076.    Unfortunately, the HP linker doesn't take into account any addend
  6077.    when generating the DLT; so accessing $LIT$+8 puts the address of
  6078.    $LIT$ into the DLT rather than the address of $LIT$+8.
  6079.  
  6080.    The end result is we can't perform relocation symbol reductions for
  6081.    any fixup which creates entries in the DLT (eg they use "T" field
  6082.    selectors).
  6083.  
  6084.    Reject reductions involving symbols with external scope; such
  6085.    reductions make life a living hell for object file editors.
  6086.  
  6087.    FIXME.  Also reject R_HPPA relocations which are 32 bits
  6088.    wide.  Helps with code lables in arrays for SOM.  (SOM BFD code
  6089.    needs to generate relocations to push the addend and symbol value
  6090.    onto the stack, add them, then pop the value off the stack and
  6091.    use it in a relocation -- yuk.  */
  6092.  
  6093. int
  6094. hppa_fix_adjustable (fixp)
  6095.      fixS *fixp;
  6096. {
  6097.   struct hppa_fix_struct *hppa_fix;
  6098.  
  6099.   hppa_fix = (struct hppa_fix_struct *) fixp->tc_fix_data;
  6100.  
  6101.   /* Reject reductions of symbols in 32bit plabel relocs.  */
  6102.   if (fixp->fx_r_type == R_HPPA && hppa_fix->fx_r_format == 32)
  6103.     return 0;
  6104.  
  6105.   /* Reject reductions of symbols in DLT relative relocs.  */
  6106.   if (hppa_fix->fx_r_field == e_tsel
  6107.       || hppa_fix->fx_r_field == e_ltsel
  6108.       || hppa_fix->fx_r_field == e_rtsel)
  6109.     return 0;
  6110.  
  6111.   if (fixp->fx_addsy && fixp->fx_addsy->bsym->flags & BSF_GLOBAL)
  6112.     return 0;
  6113.  
  6114.   /* Reject reductions of function symbols.  */
  6115.   if (fixp->fx_addsy == 0
  6116.       || (fixp->fx_addsy->bsym->flags & BSF_FUNCTION) == 0)
  6117.     return 1;
  6118.  
  6119.   return 0;
  6120. }
  6121.  
  6122. /* Return nonzero if the fixup in FIXP will require a relocation,
  6123.    even it if appears that the fixup could be completely handled
  6124.    within GAS.  */
  6125.  
  6126. int
  6127. hppa_force_relocation (fixp)
  6128.      fixS *fixp;
  6129. {
  6130.   struct hppa_fix_struct *hppa_fixp;
  6131.  
  6132.   hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
  6133. #ifdef OBJ_SOM
  6134.   if (fixp->fx_r_type == R_HPPA_ENTRY || fixp->fx_r_type == R_HPPA_EXIT)
  6135.     return 1;
  6136. #endif
  6137.  
  6138. #define stub_needed(CALLER, CALLEE) \
  6139.   ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
  6140.  
  6141.   /* It is necessary to force PC-relative calls/jumps to have a relocation
  6142.      entry if they're going to need either a argument relocation or long
  6143.      call stub.  FIXME.  Can't we need the same for absolute calls?  */
  6144.   if (fixp->fx_pcrel && fixp->fx_addsy
  6145.       && (stub_needed (((obj_symbol_type *)
  6146.             fixp->fx_addsy->bsym)->tc_data.hppa_arg_reloc,
  6147.                hppa_fixp->fx_arg_reloc)))
  6148.     return 1;
  6149.  
  6150. #undef stub_needed
  6151.  
  6152.   /* No need (yet) to force another relocations to be emitted.  */
  6153.   return 0;
  6154. }
  6155.  
  6156. /* Now for some ELF specific code.  FIXME.  */
  6157. #ifdef OBJ_ELF
  6158. /* Mark the end of a function so that it's possible to compute
  6159.    the size of the function in hppa_elf_final_processing.  */
  6160.  
  6161. static void
  6162. hppa_elf_mark_end_of_function ()
  6163. {
  6164.   /* ELF does not have EXIT relocations.  All we do is create a
  6165.      temporary symbol marking the end of the function.  */
  6166.   char *name = (char *)
  6167.     xmalloc (strlen ("L$\001end_") +
  6168.          strlen (S_GET_NAME (last_call_info->start_symbol)) + 1);
  6169.  
  6170.   if (name)
  6171.     {
  6172.       symbolS *symbolP;
  6173.  
  6174.       strcpy (name, "L$\001end_");
  6175.       strcat (name, S_GET_NAME (last_call_info->start_symbol));
  6176.  
  6177.       /* If we have a .exit followed by a .procend, then the
  6178.      symbol will have already been defined.  */
  6179.       symbolP = symbol_find (name);
  6180.       if (symbolP)
  6181.     {
  6182.       /* The symbol has already been defined!  This can
  6183.          happen if we have a .exit followed by a .procend.
  6184.  
  6185.          This is *not* an error.  All we want to do is free
  6186.          the memory we just allocated for the name and continue.  */
  6187.       xfree (name);
  6188.     }
  6189.       else
  6190.     {
  6191.       /* symbol value should be the offset of the
  6192.          last instruction of the function */
  6193.       symbolP = symbol_new (name, now_seg,
  6194.                 (valueT) (obstack_next_free (&frags)
  6195.                       - frag_now->fr_literal - 4),
  6196.                 frag_now);
  6197.  
  6198.       assert (symbolP);
  6199.       symbolP->bsym->flags = BSF_LOCAL;
  6200.       symbol_table_insert (symbolP);
  6201.     }
  6202.  
  6203.       if (symbolP)
  6204.     last_call_info->end_symbol = symbolP;
  6205.       else
  6206.     as_bad ("Symbol '%s' could not be created.", name);
  6207.  
  6208.     }
  6209.   else
  6210.     as_bad ("No memory for symbol name.");
  6211.  
  6212. }
  6213.  
  6214. /* For ELF, this function serves one purpose:  to setup the st_size
  6215.    field of STT_FUNC symbols.  To do this, we need to scan the
  6216.    call_info structure list, determining st_size in by taking the
  6217.    difference in the address of the beginning/end marker symbols.  */
  6218.  
  6219. void
  6220. elf_hppa_final_processing ()
  6221. {
  6222.   struct call_info *call_info_pointer;
  6223.  
  6224.   for (call_info_pointer = call_info_root;
  6225.        call_info_pointer;
  6226.        call_info_pointer = call_info_pointer->ci_next)
  6227.     {
  6228.       elf_symbol_type *esym
  6229.       = (elf_symbol_type *) call_info_pointer->start_symbol->bsym;
  6230.       esym->internal_elf_sym.st_size =
  6231.     S_GET_VALUE (call_info_pointer->end_symbol)
  6232.     - S_GET_VALUE (call_info_pointer->start_symbol) + 4;
  6233.     }
  6234. }
  6235. #endif
  6236.